I'm trying to work out why my app keeps throwing a null pointer exception
It gets thrown on "nextOnCorrectToggle.isChecked()", I have it declared like this in the
class declaration "ToggleButton nextOnCorrectToggle = null;
Below are the functions to assign buttons and use their values
void getFields() { questionTextView = (TextView)findViewById(R.id.questionTextView); pronunciationTextView = (TextView) findViewById(R.id.pronunciationTextView); answerButton1 = (Button) findViewById(R.id.answer1Button); answerButton2 = (Button) findViewById(R.id.answer2Button); answerButton3 = (Button) findViewById(R.id.answer3Button); answerButton4 = (Button) findViewById(R.id.answer4Button); getNextQuestionButton = (Button) findViewById(R.id.nextQuestionButton); correctSwitch = (Switch) findViewById(R.id.correctSwitch); correctAnswerTextView = (TextView) findViewById(R.id.trackCorrectTextView); trackCorrectSwitch = (Switch) findViewById(R.id.trackCorrectSwitch); trackCorrectToggle = (ToggleButton) findViewById(R.id.trackCorrectToggle); nextOnCorrectToggle = (ToggleButton) findViewById(R.id.nextCorrectToggle); } private void checkAnswer (String userAnswer) { if (userAnswer.equals(questionAnswer)) { Toast toast = Toast.makeText(context, "Correct", Toast.LENGTH_SHORT); toast.show(); if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) { if (trackCorrectSwitch.isChecked()) { incCorrect(); } if (correctSwitch.isChecked()) { nextQuestion(); } } else if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_NORMAL) { if (trackCorrectToggle.isChecked()) { incCorrect(); } if (nextOnCorrectToggle.isChecked()) { nextQuestion(); } } } else { Toast toast = Toast.makeText(context, "Incorrect", Toast.LENGTH_SHORT); toast.show(); resetCorrect(); } }
Error log
09-04 11:44:16.844 7251-7251/memory_aid.memoryaid E/AndroidRuntime: FATAL EXCEPTION: main Process: memory_aid.memoryaid, PID: 7251 java.lang.NullPointerException at memory_aid.memoryaid.questionActivityA.checkAnswer(questionActivityA.java:170) at memory_aid.memoryaid.questionActivityA.access$000(questionActivityA.java:28) at memory_aid.memoryaid.questionActivityA$4.onclick(questionActivityA.java:89) at android.view.View.performClick(View.java:4445) at android.view.View$PerformClick.run(View.java:18446) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5146) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566) at dalvik.system.NativeStart.main(Native Method)
If somebody could bring a fresh perspective to this to help me solve this problem
it would be appreciated
If more information is required please don't hesitate to ask
Any help is apppreciated
pheonixfire