Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid activity error
    primarykey
    data
    text
    <p>I am newbie in android. In android I trying to run a simple work. From my main.xml(http://pastebin.com/Mhgmpj4w) I have one button( my main.java(http://pastebin.com/b5irLVTc) ) it will switch to another activity the second.xml(http://pastebin.com/F92VxSEZ) where it will show some text ( my second.java(http://pastebin.com/MR3L5WXL) ) but there are some errors(http://pastebin.com/KH2wDh7b). I am a newbie please help me.</p> <p><strong>main.xml</strong>:</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="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Button" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>main.java:</strong></p> <pre><code> package com.rana.activities; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class Main extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button b = (Button) findViewById(android.R.id.button1); b.setOnClickListener(new OnClickListener() { public void onClick(View v) { startActivity(new Intent(Main.this, Second.class)); } }); } } </code></pre> <p><strong>second.xml:</strong></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="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is the second activity" /&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>second.java:</strong></p> <pre><code> package com.rana.activities; import android.app.Activity; import android.os.Bundle; public class Second extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.second); } } </code></pre> <p><strong>logcat:</strong></p> <pre><code> 10-29 19:19:25.377: D/AndroidRuntime(859): Shutting down VM 10-29 19:19:25.377: W/dalvikvm(859): threadid=1: thread exiting with uncaught exception (group=0x40015560) 10-29 19:19:25.397: E/AndroidRuntime(859): FATAL EXCEPTION: main 10-29 19:19:25.397: E/AndroidRuntime(859): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rana.activities/com.rana.activities.Main}: java.lang.NullPointerException 10-29 19:19:25.397: E/AndroidRuntime(859): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 10-29 19:19:25.397: E/AndroidRuntime(859): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 10-29 19:19:25.397: E/AndroidRuntime(859): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 10-29 19:19:25.397: E/AndroidRuntime(859): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 10-29 19:19:25.397: E/AndroidRuntime(859): at android.os.Handler.dispatchMessage(Handler.java:99) 10-29 19:19:25.397: E/AndroidRuntime(859): at android.os.Looper.loop(Looper.java:123) 10-29 19:19:25.397: E/AndroidRuntime(859): at android.app.ActivityThread.main(ActivityThread.java:3683) 10-29 19:19:25.397: E/AndroidRuntime(859): at java.lang.reflect.Method.invokeNative(Native Method) 10-29 19:19:25.397: E/AndroidRuntime(859): at java.lang.reflect.Method.invoke(Method.java:507) 10-29 19:19:25.397: E/AndroidRuntime(859): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 10-29 19:19:25.397: E/AndroidRuntime(859): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 10-29 19:19:25.397: E/AndroidRuntime(859): at dalvik.system.NativeStart.main(Native Method) 10-29 19:19:25.397: E/AndroidRuntime(859): Caused by: java.lang.NullPointerException 10-29 19:19:25.397: E/AndroidRuntime(859): at com.rana.activities.Main.onCreate(Main.java:18) 10-29 19:19:25.397: E/AndroidRuntime(859): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 10-29 19:19:25.397: E/AndroidRuntime(859): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 10-29 19:19:25.397: E/AndroidRuntime(859): ... 11 more &lt;-------LogCat-------------------&gt; </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.
 

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