Android ListView 中的奇怪异常

发布于 2025-01-05 15:11:18 字数 5638 浏览 1 评论 0原文

我收到异常,但无法准确了解异常发生的位置。 我进行了搜索,但无法在堆栈跟踪中获取我的项目名称。

下面是我的堆栈跟踪

02-13 15:48:23.741: W/dalvikvm(416): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-13 15:48:24.026: W/System.err(416):    android.content.res.Resources$NotFoundException: File  from xml type layout resource ID   #0x102000a
02-13 15:48:24.036: W/System.err(416):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1916)
02-13 15:48:24.036: W/System.err(416):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1871)
02-13 15:48:24.036: W/System.err(416):  at android.content.res.Resources.getLayout(Resources.java:731)
02-13 15:48:24.036: W/System.err(416):  at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
02-13 15:48:24.036: W/System.err(416):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
02-13 15:48:24.036: W/System.err(416):  at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
02-13 15:48:24.036: W/System.err(416):  at android.widget.AbsListView.obtainView(AbsListView.java:1315)
02-13 15:48:24.046: W/System.err(416):  at android.widget.ListView.makeAndAddView(ListView.java:1727)
02-13 15:48:24.046: W/System.err(416):  at android.widget.ListView.fillDown(ListView.java:652)
02-13 15:48:24.046: W/System.err(416):  at android.widget.ListView.fillFromTop(ListView.java:709)
02-13 15:48:24.046: W/System.err(416):  at android.widget.ListView.layoutChildren(ListView.java:1580)
02-13 15:48:24.046: W/System.err(416):  at android.widget.AbsListView.onLayout(AbsListView.java:1147)
02-13 15:48:24.046: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.046: W/System.err(416):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
02-13 15:48:24.046: W/System.err(416):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
02-13 15:48:24.046: W/System.err(416):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
02-13 15:48:24.046: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.046: W/System.err(416):  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:909)
02-13 15:48:24.056: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.056: W/System.err(416):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
02-13 15:48:24.056: W/System.err(416):  at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1238)
02-13 15:48:24.056: W/System.err(416):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1044)
02-13 15:48:24.056: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.056: W/System.err(416):  at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-13 15:48:24.056: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.056: W/System.err(416):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
02-13 15:48:24.066: W/System.err(416):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
02-13 15:48:24.066: W/System.err(416):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
02-13 15:48:24.066: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.076: W/System.err(416):  at    android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-13 15:48:24.076: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.076: W/System.err(416):  at    android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
02-13 15:48:24.076: W/System.err(416):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
02-13 15:48:24.076: W/System.err(416):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-13 15:48:24.076: W/System.err(416):  at android.os.Looper.loop(Looper.java:123)
02-13 15:48:24.076: W/System.err(416):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-13 15:48:24.076: W/System.err(416):  at java.lang.reflect.Method.invokeNative(Native Method)
02-13 15:48:24.086: W/System.err(416):  at java.lang.reflect.Method.invoke(Method.java:521)
02-13 15:48:24.086: W/System.err(416):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-13 15:48:24.086: W/System.err(416):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-13 15:48:24.086: W/System.err(416):  at dalvik.system.NativeStart.main(Native Method)
 02-13 15:48:24.086: W/System.err(416): Caused by: java.io.FileNotFoundException: 
 02-13 15:48:24.086: W/System.err(416):     at android.content.res.AssetManager.openXmlAssetNative(Native Method)
02-13 15:48:24.086: W/System.err(416):  at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:485)
02-13 15:48:24.086: W/System.err(416):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1898)
02-13 15:48:24.086: W/System.err(416):  ... 40 more

我的项目包名称是

com.stylingandroid.IntelligentLayout.SecondaryLayout;

我根本看不到我的包名称 在我遇到异常之前,我将其正确设置,异常是

02-13 15:39:25.756: W/System.err(379): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

我将 ListView Id 更改为 android:id="@id/android:list" 并在 java 代码中将适配器更改为

  setListAdapter(new ArrayAdapter<String>(this,android.R.id.list, STATE));
   getListView().setTextFilterEnabled(true);

My class extends ListActivity

public class StateList extends ListActivity{

期待您的回复。 谢谢。

I am getting an exception but could not get where exactly the exception occured.
I searched but could not get the my project name in the stacktrace.

Below is my stacktrace

02-13 15:48:23.741: W/dalvikvm(416): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-13 15:48:24.026: W/System.err(416):    android.content.res.Resources$NotFoundException: File  from xml type layout resource ID   #0x102000a
02-13 15:48:24.036: W/System.err(416):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1916)
02-13 15:48:24.036: W/System.err(416):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1871)
02-13 15:48:24.036: W/System.err(416):  at android.content.res.Resources.getLayout(Resources.java:731)
02-13 15:48:24.036: W/System.err(416):  at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
02-13 15:48:24.036: W/System.err(416):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
02-13 15:48:24.036: W/System.err(416):  at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
02-13 15:48:24.036: W/System.err(416):  at android.widget.AbsListView.obtainView(AbsListView.java:1315)
02-13 15:48:24.046: W/System.err(416):  at android.widget.ListView.makeAndAddView(ListView.java:1727)
02-13 15:48:24.046: W/System.err(416):  at android.widget.ListView.fillDown(ListView.java:652)
02-13 15:48:24.046: W/System.err(416):  at android.widget.ListView.fillFromTop(ListView.java:709)
02-13 15:48:24.046: W/System.err(416):  at android.widget.ListView.layoutChildren(ListView.java:1580)
02-13 15:48:24.046: W/System.err(416):  at android.widget.AbsListView.onLayout(AbsListView.java:1147)
02-13 15:48:24.046: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.046: W/System.err(416):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
02-13 15:48:24.046: W/System.err(416):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
02-13 15:48:24.046: W/System.err(416):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
02-13 15:48:24.046: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.046: W/System.err(416):  at android.widget.RelativeLayout.onLayout(RelativeLayout.java:909)
02-13 15:48:24.056: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.056: W/System.err(416):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
02-13 15:48:24.056: W/System.err(416):  at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1238)
02-13 15:48:24.056: W/System.err(416):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1044)
02-13 15:48:24.056: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.056: W/System.err(416):  at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-13 15:48:24.056: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.056: W/System.err(416):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
02-13 15:48:24.066: W/System.err(416):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
02-13 15:48:24.066: W/System.err(416):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
02-13 15:48:24.066: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.076: W/System.err(416):  at    android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-13 15:48:24.076: W/System.err(416):  at android.view.View.layout(View.java:7035)
02-13 15:48:24.076: W/System.err(416):  at    android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
02-13 15:48:24.076: W/System.err(416):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
02-13 15:48:24.076: W/System.err(416):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-13 15:48:24.076: W/System.err(416):  at android.os.Looper.loop(Looper.java:123)
02-13 15:48:24.076: W/System.err(416):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-13 15:48:24.076: W/System.err(416):  at java.lang.reflect.Method.invokeNative(Native Method)
02-13 15:48:24.086: W/System.err(416):  at java.lang.reflect.Method.invoke(Method.java:521)
02-13 15:48:24.086: W/System.err(416):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-13 15:48:24.086: W/System.err(416):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-13 15:48:24.086: W/System.err(416):  at dalvik.system.NativeStart.main(Native Method)
 02-13 15:48:24.086: W/System.err(416): Caused by: java.io.FileNotFoundException: 
 02-13 15:48:24.086: W/System.err(416):     at android.content.res.AssetManager.openXmlAssetNative(Native Method)
02-13 15:48:24.086: W/System.err(416):  at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:485)
02-13 15:48:24.086: W/System.err(416):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1898)
02-13 15:48:24.086: W/System.err(416):  ... 40 more

My project package name is

com.stylingandroid.IntelligentLayout.SecondaryLayout;

I could not see my package name at all
Before I had an exception which I set it right the exception was

02-13 15:39:25.756: W/System.err(379): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'

I changed my ListView Id to android:id="@id/android:list" and in java code I changed the adapter as

  setListAdapter(new ArrayAdapter<String>(this,android.R.id.list, STATE));
   getListView().setTextFilterEnabled(true);

My class extends ListActivity

public class StateList extends ListActivity{

Looking forward to your reply.
thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

奢欲 2025-01-12 15:11:18

似乎缺少资源 0x102000a。您需要从 R.java 反向引用该值并找到导致此问题的资源。

我还怀疑您使用了自己的 id,而不是 android.R.id.list 来标识布局 xml 文件中的资源。

请参阅 @+id/android:list 和@+id/list

ListView 并不像其他小部件那样直接。需要进行一些更详细的研究才能使其发挥作用。我经历了这个循环:)。

Seems like a resource is missing 0x102000a. You need to reverse reference this value from your R.java and find the resource that is causing this issue.

I also suspect that you have used a id of your own, and not android.R.id.list to identify your resource in your layout xml file.

Refer to What is difference between @+id/android:list and @+id/list

ListView is not as straight forward as other widgets. Takes a bit of more detailed study to get it working. I went through that cycle :).

小嗷兮 2025-01-12 15:11:18

请在 Android 开发者论坛中查看 ListView 规范:
http://developer.android.com/resources/tutorials/views/hello -listview.html

下面的方法需要一个布局资源,用于显示列表视图中的每个项目。

setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp" >
</TextView>

因此,这里每个列表项都将显示为 TextView。

Please check the ListView specs in Android developer forum:
http://developer.android.com/resources/tutorials/views/hello-listview.html

The below method needs a layout resource which is used to display each item in the listview.

setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp" >
</TextView>

So, here every list item will be shown as a TextView.

瘫痪情歌 2025-01-12 15:11:18

我也有同样的问题。我的类正在扩展 ListActivity,我更改为 Activity 并且现在正在运行。

I had the same problem. My class was extending ListActivity, I change to Activity and now is running.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文