ListView Android中的奇怪异常

时间:2012-02-13 10:39:19

标签: android android-listview android-resources

我收到异常,但无法确切地发现异常发生的地方。 我搜索但无法在stacktrace中获取我的项目名称。

下面是我的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

我的项目包名称是

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);

我的课程扩展了ListActivity

public class StateList extends ListActivity{

期待您的回复。 感谢。

3 个答案:

答案 0 :(得分:1)

请检查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。

答案 1 :(得分:1)

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

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

请参阅What is difference between @+id/android:list and @+id/list

ListView并不像其他小部件那样直截了当。需要进行一些更详细的研究才能使其正常运行。我经历了那个循环:)。

答案 2 :(得分:0)

我遇到了同样的问题。我的班级正在扩展ListActivity,我更改为Activity,现在正在运行。