Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid setonclicklistener intent null pointer exception
    primarykey
    data
    text
    <p>I'm trying to create a quiz game, but when I click on the response button, I get a <code>NullPointerException</code>.</p> <p>It seems all variables are initialized, can anyone help me?</p> <p>This is the class:</p> <pre><code>public class QActivity extends Activity { protected int qst = 0; protected int err = 0; protected String mode = ""; protected Intent intent; protected ArrayList&lt;Integer&gt; tb; protected Integer x = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_q); Button r1 = (Button) findViewById(R.id.rep1); Button r2 = (Button) findViewById(R.id.rep2); Button r3 = (Button) findViewById(R.id.rep3); TextView txt = (TextView) findViewById(R.id.questiontxt); Question q = new Question(); DatabaseHelper myDbHelper = new DatabaseHelper(this); tb = getIntent().getExtras().getIntegerArrayList("tb"); mode = getIntent().getExtras().getString("Mode"); qst = getIntent().getExtras().getInt("qst"); err = getIntent().getExtras().getInt("err"); if (mode.equals("25")) { x = 0; do { x = (int) (Math.random() * 57); } while (Verif(x, tb) == true); tb.add(x); qst += 1; try { q = myDbHelper.getQuestion(x); } catch (SQLException sqle) { throw sqle; } txt.setText(q.getQuestion()); r1.setText(q.getAnswer1()); r2.setText(q.getAnswer2()); r3.setText(q.getAnswer3()); TextView t1 = (TextView) findViewById(R.id.questid); TextView t3 = (TextView) findViewById(R.id.questnumber); intent = new Intent(this, QActivity.class); intent.putExtra("Mode", mode); intent.putExtra("qst", qst); intent.putExtra("err", err); intent.putExtra("tab", tb); } r1.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub startActivity(intent); } }); } public boolean Verif(int n, ArrayList&lt;Integer&gt; tbl) { for (Integer s : tbl) { if (s == n) return true; } return false; } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_q, menu); return true; } } </code></pre> <p>And this is LogCat output:</p> <pre><code>12-12 00:27:47.233: W/dalvikvm(7142): threadid=1: thread exiting with uncaught exception (group=0x40c471f8) 12-12 00:27:47.233: E/AndroidRuntime(7142): FATAL EXCEPTION: main 12-12 00:27:47.233: E/AndroidRuntime(7142): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dreamappz.alamalmaarefa/com.dreamappz.alamalmaarefa.QActivity}: java.lang.NullPointerException 12-12 00:27:47.233: E/AndroidRuntime(7142): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967) 12-12 00:27:47.233: E/AndroidRuntime(7142): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992) 12-12 00:27:47.233: E/AndroidRuntime(7142): at android.app.ActivityThread.access$600(ActivityThread.java:127) 12-12 00:27:47.233: E/AndroidRuntime(7142): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158) 12-12 00:27:47.233: E/AndroidRuntime(7142): at android.os.Handler.dispatchMessage(Handler.java:99) 12-12 00:27:47.233: E/AndroidRuntime(7142): at android.os.Looper.loop(Looper.java:137) 12-12 00:27:47.233: E/AndroidRuntime(7142): at android.app.ActivityThread.main(ActivityThread.java:4511) 12-12 00:27:47.233: E/AndroidRuntime(7142): at java.lang.reflect.Method.invokeNative(Native Method) 12-12 00:27:47.233: E/AndroidRuntime(7142): at java.lang.reflect.Method.invoke(Method.java:511) 12-12 00:27:47.233: E/AndroidRuntime(7142): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980) 12-12 00:27:47.233: E/AndroidRuntime(7142): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747) 12-12 00:27:47.233: E/AndroidRuntime(7142): at dalvik.system.NativeStart.main(Native Method) 12-12 00:27:47.233: E/AndroidRuntime(7142): Caused by: java.lang.NullPointerException 12-12 00:27:47.233: E/AndroidRuntime(7142): at com.dreamappz.alamalmaarefa.QActivity.Verif(QActivity.java:87) 12-12 00:27:47.233: E/AndroidRuntime(7142): at com.dreamappz.alamalmaarefa.QActivity.onCreate(QActivity.java:47) 12-12 00:27:47.233: E/AndroidRuntime(7142): at android.app.Activity.performCreate(Activity.java:4470) 12-12 00:27:47.233: E/AndroidRuntime(7142): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052) 12-12 00:27:47.233: E/AndroidRuntime(7142): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931) 12-12 00:27:47.233: E/AndroidRuntime(7142): ... 11 more </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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