Note that there are some explanatory texts on larger screens.

plurals
  1. POmy app crashes before it starts.This is a simple app in which i am making the use of intent to call another class from a previous class
    text
    copied!<p>intentTest.java:</p> <pre><code> package intentTest.xyz.com; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class intentTest extends Activity { Button b; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); b = (Button) findViewById(R.id.b); b.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { Intent intent = new Intent(intentTest.this,seond.class ); startActivity(intent); } }); } } </code></pre> <p>main.xml:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="First screen" /&gt; &lt;Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="click" android:name="@+id/b" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>seond.java:</p> <pre><code>package intentTest.xyz.com; import android.app.Activity; import android.os.Bundle; public class seond extends Activity{ /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second); } } </code></pre> <p>second.xml:</p> <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="second screen" /&gt; </code></pre> <p></p> <p>manifest.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="intentTest.xyz.com" android:versionCode="1" android:versionName="1.0"&gt; &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt; &lt;activity android:name=".intentTest" android:label="@string/app_name"&gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".seond"&gt;&lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>i get the following error code:</p> <pre><code>11-16 01:26:07.156: ERROR/AndroidRuntime(779): Uncaught handler: thread main exiting due to uncaught exception 11-16 01:26:07.166: ERROR/AndroidRuntime(779): java.lang.RuntimeException: Unable to start activity ComponentInfo{intentTest.xyz.com/intentTest.xyz.com.intentTest}: java.lang.NullPointerException 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at android.app.ActivityThread.access$2100(ActivityThread.java:116) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at android.os.Handler.dispatchMessage(Handler.java:99) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at android.os.Looper.loop(Looper.java:123) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at android.app.ActivityThread.main(ActivityThread.java:4203) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at java.lang.reflect.Method.invokeNative(Native Method) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at java.lang.reflect.Method.invoke(Method.java:521) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at dalvik.system.NativeStart.main(Native Method) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): Caused by: java.lang.NullPointerException 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at intentTest.xyz.com.intentTest.onCreate(intentTest.java:18) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364) 11-16 01:26:07.166: ERROR/AndroidRuntime(779): ... 11 more </code></pre>
 

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