android 列表视图出现问题
我正在尝试将代码写入 android,
tv=(TextView) findViewById(R.id.ringtone);
if (!hasErrors) {
setListAdapter(new ArrayAdapter<String>(FindFilesByType.this, R.layout.main,
Ringtones));
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> aView, View v,
int position, long id) {
currentPosition = position;
playRingtone(DIRECTORY+Ringtones.get(position));
}
});
但我正在关注 Logcat,并且我的应用程序强行关闭,
04-27 11:05:08.212: INFO/ActivityManager(52): Starting activity: Intent { cmp=android.com.testHTML/.FindFilesByType } 04-27 11:05:08.353: INFO/NotificationService(52): enqueueToast pkg=android.com.testHTML callback=android.app.ITransientNotification$Stub$Proxy@4394f760 duration=0 04-27 11:05:08.454: ERROR/ArrayAdapter(715): You must supply a resource ID for a TextView 04-27 11:05:08.454: WARN/dalvikvm(715): threadid=3: thread exiting with uncaught exception (group=0x4001aa28) 04-27 11:05:08.454: ERROR/AndroidRuntime(715): Uncaught handler: thread main exiting due to uncaught exception 04-27 11:05:08.473: ERROR/AndroidRuntime(715): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:347) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.AbsListView.obtainView(AbsListView.java:1273) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ListView.makeAndAddView(ListView.java:1658) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ListView.fillDown(ListView.java:637) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ListView.fillFromTop(ListView.java:694) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ListView.layoutChildren(ListView.java:1516) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.AbsListView.onLayout(AbsListView.java:1112) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.View.layout(View.java:6569) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1108) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.LinearLayout.onLayout(LinearLayout.java:920) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.View.layout(View.java:6569) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.View.layout(View.java:6569) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.LinearLayout.onLayout(LinearLayout.java:918) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.View.layout(View.java:6569) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.View.layout(View.java:6569) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.ViewRoot.performTraversals(ViewRoot.java:979) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.ViewRoot.handleMessage(ViewRoot.java:1613) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.os.Handler.dispatchMessage(Handler.java:99) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.os.Looper.loop(Looper.java:123) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.app.ActivityThread.main(ActivityThread.java:4203) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at java.lang.reflect.Method.invokeNative(Native Method) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at java.lang.reflect.Method.invoke(Method.java:521) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at dalvik.system.NativeStart.main(Native Method) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): Caused by: java.lang.ClassCastException: android.widget.LinearLayout 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:340) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): ... 30 more 04-27 11:05:08.493: INFO/Process(52): Sending signal. PID: 715 SIG: 3 04-27 11:05:08.493: INFO/dalvikvm(715): threadid=7: reacting to signal 3 04-27 11:05:08.503: ERROR/dalvikvm(715): Unable to open stack trace file '/data/anr/traces.txt': Permission denied 04-27 11:05:13.472: INFO/Process(715): Sending signal. PID: 715 SIG: 9 04-27 11:05:13.503: INFO/ActivityManager(52): Process android.com.testHTML (pid 715) has died. 04-27 11:05:13.512: INFO/WindowManager(52): WIN DEATH: Window{43885018 android.com.testHTML/android.com.testHTML.testHTMLActivity paused=false} 04-27 11:05:13.512: INFO/WindowManager(52): WIN DEATH: Window{43933640 Toast paused=false} 04-27 11:05:13.512: INFO/WindowManager(52): WIN DEATH: Window{439071b0 android.com.testHTML/android.com.testHTML.FindFilesByType paused=false} 04-27 11:05:13.592: INFO/ActivityManager(52): Start proc android.com.testHTML for activity android.com.testHTML/.testHTMLActivity: pid=750 uid=10024 gids={3003, 1015} 04-27 11:05:13.784: INFO/jdwp(750): received file descriptor 20 from ADB 04-27 11:05:13.913: WARN/UsageStats(52): Something wrong here, didn't expect android.com.testHTML to be resumed 04-27 11:05:14.503: WARN/InputManagerService(52): Got RemoteException sending setActive(false) notification to pid 715 uid 10024 04-27 11:05:14.643: INFO/ActivityManager(52): Displayed activity android.com.testHTML/.testHTMLActivity: 1139 ms (total 6398 ms)
我在做什么错?
提前致谢
i am trying folling code into android
tv=(TextView) findViewById(R.id.ringtone);
if (!hasErrors) {
setListAdapter(new ArrayAdapter<String>(FindFilesByType.this, R.layout.main,
Ringtones));
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> aView, View v,
int position, long id) {
currentPosition = position;
playRingtone(DIRECTORY+Ringtones.get(position));
}
});
but i am getting following Logcat and my application close forcefully close
04-27 11:05:08.212: INFO/ActivityManager(52): Starting activity: Intent { cmp=android.com.testHTML/.FindFilesByType } 04-27 11:05:08.353: INFO/NotificationService(52): enqueueToast pkg=android.com.testHTML callback=android.app.ITransientNotification$Stub$Proxy@4394f760 duration=0 04-27 11:05:08.454: ERROR/ArrayAdapter(715): You must supply a resource ID for a TextView 04-27 11:05:08.454: WARN/dalvikvm(715): threadid=3: thread exiting with uncaught exception (group=0x4001aa28) 04-27 11:05:08.454: ERROR/AndroidRuntime(715): Uncaught handler: thread main exiting due to uncaught exception 04-27 11:05:08.473: ERROR/AndroidRuntime(715): java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:347) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.AbsListView.obtainView(AbsListView.java:1273) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ListView.makeAndAddView(ListView.java:1658) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ListView.fillDown(ListView.java:637) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ListView.fillFromTop(ListView.java:694) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ListView.layoutChildren(ListView.java:1516) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.AbsListView.onLayout(AbsListView.java:1112) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.View.layout(View.java:6569) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1108) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.LinearLayout.onLayout(LinearLayout.java:920) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.View.layout(View.java:6569) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.View.layout(View.java:6569) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.LinearLayout.onLayout(LinearLayout.java:918) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.View.layout(View.java:6569) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.FrameLayout.onLayout(FrameLayout.java:333) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.View.layout(View.java:6569) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.ViewRoot.performTraversals(ViewRoot.java:979) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.view.ViewRoot.handleMessage(ViewRoot.java:1613) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.os.Handler.dispatchMessage(Handler.java:99) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.os.Looper.loop(Looper.java:123) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.app.ActivityThread.main(ActivityThread.java:4203) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at java.lang.reflect.Method.invokeNative(Native Method) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at java.lang.reflect.Method.invoke(Method.java:521) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at dalvik.system.NativeStart.main(Native Method) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): Caused by: java.lang.ClassCastException: android.widget.LinearLayout 04-27 11:05:08.473: ERROR/AndroidRuntime(715): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:340) 04-27 11:05:08.473: ERROR/AndroidRuntime(715): ... 30 more 04-27 11:05:08.493: INFO/Process(52): Sending signal. PID: 715 SIG: 3 04-27 11:05:08.493: INFO/dalvikvm(715): threadid=7: reacting to signal 3 04-27 11:05:08.503: ERROR/dalvikvm(715): Unable to open stack trace file '/data/anr/traces.txt': Permission denied 04-27 11:05:13.472: INFO/Process(715): Sending signal. PID: 715 SIG: 9 04-27 11:05:13.503: INFO/ActivityManager(52): Process android.com.testHTML (pid 715) has died. 04-27 11:05:13.512: INFO/WindowManager(52): WIN DEATH: Window{43885018 android.com.testHTML/android.com.testHTML.testHTMLActivity paused=false} 04-27 11:05:13.512: INFO/WindowManager(52): WIN DEATH: Window{43933640 Toast paused=false} 04-27 11:05:13.512: INFO/WindowManager(52): WIN DEATH: Window{439071b0 android.com.testHTML/android.com.testHTML.FindFilesByType paused=false} 04-27 11:05:13.592: INFO/ActivityManager(52): Start proc android.com.testHTML for activity android.com.testHTML/.testHTMLActivity: pid=750 uid=10024 gids={3003, 1015} 04-27 11:05:13.784: INFO/jdwp(750): received file descriptor 20 from ADB 04-27 11:05:13.913: WARN/UsageStats(52): Something wrong here, didn't expect android.com.testHTML to be resumed 04-27 11:05:14.503: WARN/InputManagerService(52): Got RemoteException sending setActive(false) notification to pid 715 uid 10024 04-27 11:05:14.643: INFO/ActivityManager(52): Displayed activity android.com.testHTML/.testHTMLActivity: 1139 ms (total 6398 ms)
what is wrong i am doing?
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
朋友,您的问题是您正在使用 r.layout.main 作为列表行。
您必须创建一个单独的 listrow 布局,其中仅提及 textview
并将其作为布局传递
您的错误在这一行
创建一个布局,例如 listrow.xml
并更改您的行
well friend your problem is you are using r.layout.main for list row.
you have to create a separete listrow layout where you mention only textview
and pass it as a layout
your error is on this line
create a layout say listrow.xml
and change your line
logcat 明确指出您需要为 textview 提供资源 id,因为您提供的是线性布局(我的猜测是因为它抛出 ClassCastException),我相信您的 main.xml 是线性布局而不是文本视图。而是尝试
R.id.ringtone
The logcat clearly states that you need to provide the resource id for a textview, where as what you are providing is a linearlayout (My guess since it throws ClassCastException) I believe you main.xml is a linearlayout and not a textview. Instead try
R.id.ringtone
您的问题在以下几行中进行了描述:
这可能意味着您正在使用某些东西作为
LinearLayout
,但它不是一个。(大多数时候你会得到 ClassCastException,你正在做类似的事情
foobar = (LinearLayout) someCode();
)You problem is described in these lines:
It probably means that you are using something as a
LinearLayout
, while it isn't one.(most of the time you get a ClassCastException you're doing something like
foobar = (LinearLayout) someCode();
)