Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException Android
    text
    copied!<p>While running the application I'm getting these errors</p> <blockquote> <p>10-09 10:20:57.138: ERROR/AndroidRuntime(282): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rika/com.rika.LatihanActivity}: java.lang.NullPointerException</p> <p>10-09 10:20:57.138: ERROR/AndroidRuntime(282): Caused by: java.lang.NullPointerException</p> </blockquote> <p>Please anyone help me to solve this problem.</p> <p>Its the activity class</p> <pre><code>public class LatihanActivity extends Activity{ private RadioButton radioButton; private TextView quizQuestion; private int rowIndex = 1; private int questNo=0; private boolean checked=false; private boolean flag=true; private RadioGroup radioGroup; String[] corrAns = new String[5]; final DatabaseHelper db = new DatabaseHelper(this); Cursor c1; Cursor c2; Cursor c3; int counter=1; String label; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); String options[] = new String[19]; final RadioGroup radiogroup = (RadioGroup) findViewById(R.id.rdbGp1); // layout params to use when adding each radio button LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams( RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT); try { db.createDataBase(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } quizQuestion = (TextView) findViewById(R.id.TextView01); displayQuestion(); /*Displays the next options and sets listener on next button*/ Button btnNext = (Button) findViewById(R.id.btnNext); btnNext.setOnClickListener(btnNext_Listener); /*Saves the selected values in the database on the save button*/ Button btnSave = (Button) findViewById(R.id.btnSave); btnSave.setOnClickListener(btnSave_Listener); c3 = db.getCorrAns(); for (int i=0;i&lt;=4;i++) { corrAns[i]=c3.getString(0); c3.moveToNext(); } radioGroup = (RadioGroup) findViewById(R.id.rdbGp1); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub for(int i=0; i&lt;radiogroup.getChildCount() ; i++) { RadioButton btn = (RadioButton) radioGroup.getChildAt(i); String text; if (btn.isPressed() &amp;&amp; btn.isChecked() &amp;&amp; questNo &lt; 5) { Log.e("corrAns[questNo]",corrAns[questNo]); if (corrAns[questNo].equals(btn.getText()) &amp;&amp; flag==true) { flag=false; checked = true; } else if(checked==true) { flag=true; checked = false; } } } } }); } /*Called when next button is clicked*/ private View.OnClickListener btnNext_Listener= new View.OnClickListener() { @Override public void onClick(View v) { flag=true; checked = false; questNo++; if (questNo &lt; 5) { c1.moveToNext(); displayQuestion(); } } }; private View.OnClickListener btnSave_Listener= new View.OnClickListener() { @Override public void onClick(View v) {} }; private void displayQuestion() { //Fetching data quiz data and incrementing on each click c1=db.getQuiz_Content(rowIndex); c2 =db.getAns(rowIndex++); quizQuestion.setText(c1.getString(0)); radioGroup.removeAllViews(); for (int i=0;i&lt;=3;i++) { //Generating and adding 4 radio buttons dynamically radioButton = new RadioButton(this); radioButton.setText(c2.getString(0)); radioButton.setId(i); c2.moveToNext(); radioGroup.addView(radioButton); } } } </code></pre> <p>All these issues happened when run the application</p> <blockquote> <p>10-09 11:13:15.128: ERROR/HierarchicalStateMachine(68): TetherMaster - unhandledMessage: msg.what=3</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): FATAL EXCEPTION: main</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rika/com.rika.LatihanActivity}: java.lang.NullPointerException</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at android.app.ActivityThread.access$2300(ActivityThread.java:125)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at android.os.Handler.dispatchMessage(Handler.java:99)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at android.os.Looper.loop(Looper.java:123)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at android.app.ActivityThread.main(ActivityThread.java:4627)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at java.lang.reflect.Method.invokeNative(Native Method)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at java.lang.reflect.Method.invoke(Method.java:521)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at dalvik.system.NativeStart.main(Native Method)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): Caused by: java.lang.NullPointerException</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at com.rika.LatihanActivity.displayQuestion(LatihanActivity.java:198)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at com.rika.LatihanActivity.onCreate(LatihanActivity.java:69)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)</p> <p>10-09 11:13:56.556: ERROR/AndroidRuntime(282): ... 11 more</p> </blockquote>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload