This method renders some text onto a Canvas every time the screen refreshes using a SurfaceView and is supposed to return when the database cursor is closed (if cursorClosed
). But as you can see from the LogCat, it doesnt. Even though cursorClosed
is true as evidenced by the System.out.println(cursorClosed)
call it arrives at this call when it should have returned after the if-statement. Can anybody explain to me why this is happening? Thank you for every hint!
This is my code:
public void present(float deltaTime) {
Graphics graphics = game.getGraphics();
graphics.drawBackground(Assets.background);
if (cursorClosed)
return;
System.out.println(cursorClosed);
if (picture != null) {
graphics.drawPixmap(picture, 40, 280, 50);
}
if (!translated) {
graphics.renderText(14, cursor.getString(1), 160, 300);
} else {
System.out.println("cursorClosed: " + cursorClosed);
graphics.renderText(14, cursor.getString(2), 160, 300);
graphics.drawPixmap(Assets.nextButton, 250, 310, 420);
}
}
This is the LogCat:
07-20 19:21:25.950 21343-21378/com.melonman.wordsandphrases I/System.out: false
07-20 19:21:25.950 21343-21343/com.melonman.wordsandphrases I/System.out: 1
07-20 19:21:25.950 21343-21378/com.melonman.wordsandphrases I/System.out: cursorClosed: true
07-20 19:21:25.950 21343-21378/com.melonman.wordsandphrases E/AndroidRuntime: FATAL EXCEPTION: Thread-35292
Process: com.melonman.wordsandphrases, PID: 21343
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.String android.database.Cursor.getString(int)' on a null object reference
at com.melonman.wordsandphrases.wordsandphrasesapp.LessonScreen1.present(LessonScreen1.java:83)
at com.melonman.wordsandphrases.framework.impl.AndroidFastRenderView.run(AndroidFastRenderView.java:46)
at java.lang.Thread.run(Thread.java:818)