开发者

Can't start ListActivity via Intent

I have 2 activities. First activity extends Activity and second extends ListActivity.

I need to call ListActivity from the Activity class

I have tried the following.

Intent intent = new Intent(firstclassname.this, secongclassname.class);

startActivity(intent);

I've added an entry in the manifest file but it doen't work.

That same code works for the Activity class (if the second class extends ListActivity)

I got following Logcat output

04-26 15:51:48.235: INFO/ActivityManager(52): Starting activity: Intent { cmp=android.com.testHTML/.FindFilesByType }
04-26 15:51:48.395: ERROR/ArrayAdapter(3113): You must supply a resource ID for a TextView
04-26 15:51:48.395: WARN/dalvikvm(3113): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
04-26 15:51:48.405: ERROR/AndroidRuntime(3113): Uncaught handler: thread main exiting due to uncaught exception
04-26 15:51:48.414: ERROR/AndroidRuntime(3113): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:347)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.ArrayAdapter.getView(ArrayA开发者_如何学JAVAdapter.java:323)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.AbsListView.obtainView(AbsListView.java:1273)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.ListView.makeAndAddView(ListView.java:1658)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.ListView.fillDown(ListView.java:637)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.ListView.fillFromTop(ListView.java:694)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.ListView.layoutChildren(ListView.java:1516)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.AbsListView.onLayout(AbsListView.java:1112)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.view.View.layout(View.java:6569)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1108)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.LinearLayout.onLayout(LinearLayout.java:920)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.view.View.layout(View.java:6569)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.view.View.layout(View.java:6569)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.LinearLayout.onLayout(LinearLayout.java:918)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.view.View.layout(View.java:6569)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.view.View.layout(View.java:6569)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.view.ViewRoot.performTraversals(ViewRoot.java:979)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1613)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.os.Looper.loop(Looper.java:123)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.app.ActivityThread.main(ActivityThread.java:4203)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at java.lang.reflect.Method.invokeNative(Native Method)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at java.lang.reflect.Method.invoke(Method.java:521)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at dalvik.system.NativeStart.main(Native Method)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113): Caused by: java.lang.ClassCastException: android.widget.LinearLayout
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:340)
04-26 15:51:48.414: ERROR/AndroidRuntime(3113):     ... 30 more
04-26 15:51:48.436: INFO/Process(52): Sending signal. PID: 3113 SIG: 3
04-26 15:51:48.446: INFO/dalvikvm(3113): threadid=7: reacting to signal 3
04-26 15:51:48.446: ERROR/dalvikvm(3113): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
04-26 15:51:58.289: WARN/ActivityManager(52): Launch timeout has expired, giving up wake lock!
04-26 15:51:58.289: WARN/ActivityManager(52): Activity idle timeout for HistoryRecord{4391c898 android.com.testHTML/.FindFilesByType}

What am I doing wrong?


Your activity is properly started.

The problem is in ArrayAdapter that you are using. You are not providing the resource id of the TextView.

Check out which constructor you are using and provide the correct parameters.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜