Note that there are some explanatory texts on larger screens.

plurals
  1. PONullPointerException when i try open an activity with an Intent
    primarykey
    data
    text
    <p>I have made an android app in wich an aactivity opens another.The one that opens is:</p> <pre><code>package com.tendariuspro.oz; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class Second extends Activity { Button btnYes; Button btnNo; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.second); btnYes = (Button) findViewById (R.id.btnYesTwo); btnNo = (Button) findViewById (R.id.btnNoTwo); btnYes.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub try { Class&lt;?&gt; cc = Class.forName("com.tendariuspro.oz.Tenis"); Intent ii = new Intent(Second.this, cc); startActivity(ii); finish(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); btnNo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub try { Class&lt;?&gt; c = Class.forName("com.tendariuspro.oz.Baschet"); Intent i = new Intent(Second.this, c); startActivity(i); finish(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } } </code></pre> <p>and the one that is opened by the btnYes is:</p> <pre><code>package com.tendariuspro.oz; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class Baschet extends Activity{ Button btnYes; Button btnNo; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.baschet); btnYes = (Button) findViewById (R.id.btnYesOne); btnNo = (Button) findViewById (R.id.btnNoOne); btnYes.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub try { Class&lt;?&gt; cc = Class.forName("com.tendariuspro.oz.Razvan"); Intent ii = new Intent(Baschet.this, cc); startActivity(ii); finish(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); btnNo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub try { Class&lt;?&gt; c = Class.forName("com.tendariuspro.oz.Rares"); Intent i = new Intent(Baschet.this, c); startActivity(i); finish(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } } </code></pre> <p>NB: the activity that is opened by the btnNo is similar to this!</p> <p>But when i press the btnNo or btnYes it gives me a NullPointerException at line 22 (btnYes) in both activities!</p> <p>Can you help me please!</p> <p>Here is the LogCat:</p> <pre><code>06-16 07:59:09.395: E/AndroidRuntime(1465): FATAL EXCEPTION: main 06-16 07:59:09.395: E/AndroidRuntime(1465): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tendariuspro.oz/com.tendariuspro.oz.Baschet}: java.lang.NullPointerException 06-16 07:59:09.395: E/AndroidRuntime(1465): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 06-16 07:59:09.395: E/AndroidRuntime(1465): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 06-16 07:59:09.395: E/AndroidRuntime(1465): at android.app.ActivityThread.access$600(ActivityThread.java:141) 06-16 07:59:09.395: E/AndroidRuntime(1465): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 06-16 07:59:09.395: E/AndroidRuntime(1465): at android.os.Handler.dispatchMessage(Handler.java:99) 06-16 07:59:09.395: E/AndroidRuntime(1465): at android.os.Looper.loop(Looper.java:137) 06-16 07:59:09.395: E/AndroidRuntime(1465): at android.app.ActivityThread.main(ActivityThread.java:5041) 06-16 07:59:09.395: E/AndroidRuntime(1465): at java.lang.reflect.Method.invokeNative(Native Method) 06-16 07:59:09.395: E/AndroidRuntime(1465): at java.lang.reflect.Method.invoke(Method.java:511) 06-16 07:59:09.395: E/AndroidRuntime(1465): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 06-16 07:59:09.395: E/AndroidRuntime(1465): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 06-16 07:59:09.395: E/AndroidRuntime(1465): at dalvik.system.NativeStart.main(Native Method) 06-16 07:59:09.395: E/AndroidRuntime(1465): Caused by: java.lang.NullPointerException 06-16 07:59:09.395: E/AndroidRuntime(1465): at com.tendariuspro.oz.Baschet.onCreate(Baschet.java:22) 06-16 07:59:09.395: E/AndroidRuntime(1465): at android.app.Activity.performCreate(Activity.java:5104) 06-16 07:59:09.395: E/AndroidRuntime(1465): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) 06-16 07:59:09.395: E/AndroidRuntime(1465): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) 06-16 07:59:09.395: E/AndroidRuntime(1465): ... 11 more </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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