Since you are extending ListActivity you need to have an Listview with android:id="@android:id/list"
.
if you want to use @+id/lst_main
then dont extend ListActivity, just extended Activity.
Also you need to inflate the listview using the adapter
Question
what need with ListActivity on this code that not return "unfortunately,app has stopped"
& please dont NAY!
package com.example.app;
Imports............
public class Main extends ListActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onListItemClick(ListView parent, View v,
int position, long id)
{ }
}
> 09-12 00:52:51.373: D/AndroidRuntime(1871): Shutting down VM 09-12 00:52:51.373: W/dalvikvm(1871): threadid=1: thread exiting with uncaught exception (group=0x409c01f8) 09-12 00:52:51.393: E/AndroidRuntime(1871): FATAL EXCEPTION: main 09-12 00:52:51.393: E/AndroidRuntime(1871): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.rss/com.example.rss.Main}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 09-12 00:52:51.393: E/AndroidRuntime(1871): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956) 09-12 00:52:51.393: E/AndroidRuntime(1871): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 09-12 00:52:51.393: E/AndroidRuntime(1871): at android.app.ActivityThread.access$600(ActivityThread.java:123) 09-12 00:52:51.393: E/AndroidRuntime(1871): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 09-12 00:52:51.393: E/AndroidRuntime(1871): at android.os.Handler.dispatchMessage(Handler.java:99) 09-12 00:52:51.393: E/AndroidRuntime(1871): at android.os.Looper.loop(Looper.java:137) 09-12 00:52:51.393: E/AndroidRuntime(1871): at android.app.ActivityThread.main(ActivityThread.java:4424) 09-12 00:52:51.393: E/AndroidRuntime(1871): at java.lang.reflect.Method.invokeNative(Native Method) 09-12 00:52:51.393: E/AndroidRuntime(1871): at java.lang.reflect.Method.invoke(Method.java:511) 09-12 00:52:51.393: E/AndroidRuntime(1871): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 09-12 00:52:51.393: E/AndroidRuntime(1871): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 09-12 00:52:51.393: E/AndroidRuntime(1871): at dalvik.system.NativeStart.main(Native Method) 09-12 00:52:51.393: E/AndroidRuntime(1871): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list' 09-12 00:52:51.393: E/AndroidRuntime(1871): at android.app.ListActivity.onContentChanged(ListActivity.java:243) 09-12 00:52:51.393: E/AndroidRuntime(1871): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:254) 09-12 00:52:51.393: E/AndroidRuntime(1871): at android.app.Activity.setContentView(Activity.java:1835) 09-12 00:52:51.393: E/AndroidRuntime(1871): at com.example.rss.Main.onCreate(Main.java:26) 09-12 00:52:51.393: E/AndroidRuntime(1871): at android.app.Activity.performCreate(Activity.java:4465) 09-12 00:52:51.393: E/AndroidRuntime(1871): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 09-12 00:52:51.393: E/AndroidRuntime(1871): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 09-12 00:52:51.393: E/AndroidRuntime(1871): ... 11 more
Solution
Since you are extending ListActivity you need to have an Listview with android:id="@android:id/list"
.
if you want to use @+id/lst_main
then dont extend ListActivity, just extended Activity.
Also you need to inflate the listview using the adapter
OTHER TIPS
You must set attribute to your ListView
android:id="@android:id/list"
Also don't forget to register your Activity in manifest