开发者

Getting the Runtime exception in the application

I am getting the Run time exception in my application and I have tried a lot to sort it out but couldn't do it.

Here is the code where I am getting the error:

public class FirstDemo extends ListActivity
{
    private ListView Lv02;
    private String Lv_Arr02[]={ "darshan", "sunil", "viral", "jaimin", "aashish", "jaydev", "bhavesh"};
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mylistview);  ( Here I am getting the Exception )
        Lv02=(ListView) findViewById(R.id.lstvw_mylist);
}
}

My Stack Trace is as under:


12-30 11:21:09.525: ERROR/AndroidRuntime(517): FATAL EXCEPTION: main
12-30 11:21:09.525: ERROR/AndroidRuntime(517): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.mytabhostdemo/com.android.mytabhostdemo.FirstDemo}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.widget.TabHost.setCurrentTab(TabHost.java:323)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.view.View.performClick(View.java:2408)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.view.View$PerformClick.run(View.java:8816)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.os.Handler.handleCallback(Handler.java:587)
12-30 11:21:09.525: ERROR/AndroidRuntime开发者_开发知识库(517):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.os.Looper.loop(Looper.java:123)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.app.ActivityThread.main(ActivityThread.java:4627)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at java.lang.reflect.Method.invokeNative(Native Method)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at java.lang.reflect.Method.invoke(Method.java:521)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at dalvik.system.NativeStart.main(Native Method)
12-30 11:21:09.525: ERROR/AndroidRuntime(517): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.app.ListActivity.onContentChanged(ListActivity.java:245)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:201)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.app.Activity.setContentView(Activity.java:1647)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at com.android.mytabhostdemo.FirstDemo.onCreate(FirstDemo.java:17)  (Here I think)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-30 11:21:09.525: ERROR/AndroidRuntime(517):     ... 18 more

It would be great if anybody could help me. Thanks, david


In your XML file your top element must be a ListView since you derive from ListActivity.

example:

<ListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/list">
</ListView>

When deriving from specific activities Android expects there to be a specific definition in your layout XML file with a predefined ID.

If you post your XML we can fix it for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜