Fastian
Fastian

Reputation: 1

java.lang.RuntimeException:Unable to start activity component info (Android)

I am getting the following exception in my android code but i can't figure it out. I have extended my Home activity with TabActivity and receiving intents in it from MainActivity. In the tab3 i have passed intents to another activity which will start on selecting the tab3. The data from the intent is being received in that activity. I have checked it by Log. This received data will be shown in ListView of that activity. But unfortunately my app breaks down. Any help regarding this?
Here is my logcat.

01-24 14:36:34.880: E/AndroidRuntime(1147): FATAL EXCEPTION: main
01-24 14:36:34.880: E/AndroidRuntime(1147): Process: com.example.app, PID: 1147
01-24 14:36:34.880: E/AndroidRuntime(1147): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.Home1}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.CameraList}: java.lang.NullPointerException
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.ActivityThread.access$700(ActivityThread.java:135)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.os.Handler.dispatchMessage(Handler.java:102)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.os.Looper.loop(Looper.java:137)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.ActivityThread.main(ActivityThread.java:4998)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at java.lang.reflect.Method.invokeNative(Native Method)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at java.lang.reflect.Method.invoke(Method.java:515)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at dalvik.system.NativeStart.main(Native Method)
01-24 14:36:34.880: E/AndroidRuntime(1147): Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.app/com.example.app.CameraList}: java.lang.NullPointerException
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2019)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:749)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.widget.TabHost.setCurrentTab(TabHost.java:413)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.widget.TabHost.addTab(TabHost.java:240)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at com.example.app.Home1.setNewTab(Home1.java:136)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at com.example.app.Home1.onCreate(Home1.java:83)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.Activity.performCreate(Activity.java:5243)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
01-24 14:36:34.880: E/AndroidRuntime(1147):     ... 11 more
01-24 14:36:34.880: E/AndroidRuntime(1147): Caused by: java.lang.NullPointerException
01-24 14:36:34.880: E/AndroidRuntime(1147):     at com.example.app.CameraList.onCreate(CameraList.java:40)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.Activity.performCreate(Activity.java:5243)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-24 14:36:34.880: E/AndroidRuntime(1147):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
01-24 14:36:34.880: E/AndroidRuntime(1147):     ... 22 more

And this is the place where i used tabs in Home activity..

String [] names;
names = intent.getStringArrayExtra("name");
    if(tag.equals("tab3"))
    {
        Intent ListIntent = new Intent(this, List.class);
        ListIntent.putExtra("itemName", names);
        tabSpec.setContent(ListIntent);
        tabHost.addTab(tabSpec);
    }

The activity where I recieve the intent in the OnCreate method:

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cam_list);

    //Log.i("cam","List");

    Intent intent = getIntent();
    name = intent.getStringArrayExtra("camName");
    //Log.i("cam", name[1]);
    url = intent.getStringArrayExtra("url");

    list = (ListView)findViewById(R.id.listView);

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.cam_list,R.id.text1, name);
    list.setAdapter(adapter);
    /*list.setOnItemClickListener(new OnItemClickListener() {

         @Override
         public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {

              // ListView Clicked item value
              String  itemValue    = (String) list.getItemAtPosition(position);
              String camUrl = url[position];

               // Show Alert 
               Toast.makeText(getApplicationContext(),camUrl,Toast.LENGTH_LONG).show();
         }
    });*/
}

Upvotes: 0

Views: 2506

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007584

If you get a NullPointerException on a View you retrieved from findViewById(), Android is telling you that the View does not exist. There are two main possibilities here:

  1. The View really does not exist, such as failing to call setContentView() when you needed to.

  2. If you are using Eclipse, sometimes the R constants get out of sync with the contents of your APK file. To fix this, choose Project > Clean from the Eclipse main menu, then try running your app again. Fortunately, I have not seen this behavior with Android Studio (thank $DEITY for small favors...).

Upvotes: 1

Related Questions