user802023
user802023

Reputation: 201

Error in using startActivity

I have the following code that crashes upon click. When startActivity(...) is commented out, it does not crash (but does not work). But the Activity is empty! I'm clueless as to what's going on. Taking out the Bundle does not work.

Anyone have any ideas?

In RSSReader.java

 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,ShowDescription.class);

     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());
     b.putString("pubdate", feed.getItem(position).getPubDate());

     itemintent.putExtra("android.intent.extra.INTENT", b);

     startActivity(itemintent);
 }

ShowDescription.java:

import android.app.Activity;
public class ShowDescription extends Activity 
{
}

Upvotes: 0

Views: 102

Answers (3)

h4rpur
h4rpur

Reputation: 341

You'll have to declare the second activity in your manifest like so:

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" 
    android:theme="@android:style/Theme.Light">
    <activity
        android:label="@string/app_name"
        android:name=".MainActivity" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:label="@string/app_name"
        android:name=".ShowDescription" >
    </activity>
</application>

and also make sure it's a valid activity as Sid said:

import android.app.Activity;
public class ShowDescription extends Activity 
{
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //grab your Bundle stuff if you want to handle it that way:
        String title = savedInstanceState.getString("title");
        //etc.

        //Inflate/create your layouts here and set the contentview.
        setContentView(showDescLayout);
    }
}

Upvotes: 0

Wizetux
Wizetux

Reputation: 756

Make sure that you have added the ShowDescription activity to the Manifest file.

Upvotes: 0

Sid
Sid

Reputation: 7631

I think you at least need the following in your activity:

protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);


     }

Upvotes: 1

Related Questions