Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to debug "java.lang.RuntimeException: Unable to start activity ComponentInfo"?
    text
    copied!<p>I am trying to call a new Activity("OtherActivity") when I click on the action item in the action bar... but it gives me java.lang.RuntimeException: Unable to start activity ComponentInfo.</p> <p>I have specified the both the MainActivity and OtherActivity in the manifest.xml file.</p> <pre><code>package com.example.notice; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn = (Button)findViewById(R.id.action_settings); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent i = new Intent(MainActivity.this,OtherActivity.class); startActivity(i); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } </code></pre> <p>And this is my LogCat</p> <pre><code>12-08 01:51:38.118: E/AndroidRuntime(2823): FATAL EXCEPTION: main 12-08 01:51:38.118: E/AndroidRuntime(2823): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.notice/com.example.notice.MainActivity}: java.lang.NullPointerException 12-08 01:51:38.118: E/AndroidRuntime(2823): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 12-08 01:51:38.118: E/AndroidRuntime(2823): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 12-08 01:51:38.118: E/AndroidRuntime(2823): at android.app.ActivityThread.access$600(ActivityThread.java:141) 12-08 01:51:38.118: E/AndroidRuntime(2823): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 12-08 01:51:38.118: E/AndroidRuntime(2823): at android.os.Handler.dispatchMessage(Handler.java:99) 12-08 01:51:38.118: E/AndroidRuntime(2823): at android.os.Looper.loop(Looper.java:137) 12-08 01:51:38.118: E/AndroidRuntime(2823): at android.app.ActivityThread.main(ActivityThread.java:5103) 12-08 01:51:38.118: E/AndroidRuntime(2823): at java.lang.reflect.Method.invokeNative(Native Method) 12-08 01:51:38.118: E/AndroidRuntime(2823): at java.lang.reflect.Method.invoke(Method.java:525) 12-08 01:51:38.118: E/AndroidRuntime(2823): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 12-08 01:51:38.118: E/AndroidRuntime(2823): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 12-08 01:51:38.118: E/AndroidRuntime(2823): at dalvik.system.NativeStart.main(Native Method) 12-08 01:51:38.118: E/AndroidRuntime(2823): Caused by: java.lang.NullPointerException 12-08 01:51:38.118: E/AndroidRuntime(2823): at com.example.notice.MainActivity.onCreate(MainActivity.java:17) 12-08 01:51:38.118: E/AndroidRuntime(2823): at android.app.Activity.performCreate(Activity.java:5133) 12-08 01:51:38.118: E/AndroidRuntime(2823): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 12-08 01:51:38.118: E/AndroidRuntime(2823): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175) 12-08 01:51:38.118: E/AndroidRuntime(2823): ... 11 more </code></pre> <p>OtherActivity</p> <pre><code>package com.example.notice; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class OtherActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_other); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.other, menu); return true; } </code></pre> <p>}</p>
 

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