null pointer exception when starting new activity

Posted by acithium on Stack Overflow See other posts from Stack Overflow or by acithium
Published on 2010-12-28T03:01:05Z Indexed on 2010/12/28 3:54 UTC
Read the original article Hit count: 267

Okay, I'm getting a null pointer exception when I start my third activity. Here is the LogCat message:

12-28 04:38:00.350: ERROR/AndroidRuntime(776): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.acithium.main/com.acithium.rss.ShowDescription}: java.lang.NullPointerException
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2401)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at android.app.ActivityThread.access$2100(ActivityThread.java:116)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at android.os.Looper.loop(Looper.java:123)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at android.app.ActivityThread.main(ActivityThread.java:4203)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at java.lang.reflect.Method.invokeNative(Native Method)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at java.lang.reflect.Method.invoke(Method.java:521)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at dalvik.system.NativeStart.main(Native Method)
12-28 04:38:00.350: ERROR/AndroidRuntime(776): Caused by: java.lang.NullPointerException
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at com.acithium.rss.ShowDescription.onCreate(ShowDescription.java:48)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
12-28 04:38:00.350: ERROR/AndroidRuntime(776):     ... 11 more

Here is the section of code where I call the activity:

public void onItemClick(AdapterView parent, View v, int position, long id)
 {
     Log.i(tag,"item clicked! [" + feed.getItem(position).getTitle() + "]");

     Intent itemintent = new Intent(this,com.acithium.rss.ShowDescription.class);
     //Intent itemintent = new Intent();
     //itemintent.setClassName("com.acithium.main", "com.acithium.rss.ShowDescription");
     Bundle b = new Bundle();
     b.putString("title", feed.getItem(position).getTitle());
     b.putString("description", feed.getItem(position).getDescription());
     b.putString("link", feed.getItem(position).getLink());
     itemintent.putExtra("android.intent.extra.INTENT", b);

     startActivityForResult(itemintent,0);
 }

And here is new activity class that is called:

public class ShowDescription extends Activity 
{

    public void onCreate(Bundle icicle) 
    {
        super.onCreate(icicle);
        setContentView(R.layout.showdescription);

        String theStory = null;


        Intent startingIntent = getIntent();


        if (startingIntent != null)
        {
            Bundle b = startingIntent.getBundleExtra("android.intent.extra.INTENT");
            if (b == null)
            {
                theStory = "bad bundle?";
            }
            else
            {
                theStory =  b.getString("title") + "\n\n" + b.getString("description") + "\n\nMore information:\n" + b.getString("link");
            }
        }
        else
        {
            theStory = "Information Not Found.";

        }
        TextView db= (TextView) findViewById(R.id.storybox);
        db.setText(theStory);

        Button backbutton = (Button) findViewById(R.id.back);

        backbutton.setOnClickListener(new Button.OnClickListener() 
        {
            public void onClick(View v) 
            {
                finish();
            }
        });        
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about android