资源未找到异常android

时间:2013-01-04 07:55:44

标签: android android-layout spinner

当我尝试为微调器添加自定义视图时,我得到以下异常。这是日志猫

01-04 12:37:11.299: E/AndroidRuntime(759): FATAL EXCEPTION: main
01-04 12:37:11.299: E/AndroidRuntime(759): android.content.res.Resources$NotFoundException: File res/drawable-hdpi/spinner.png from xml type layout resource ID #0x7f020055
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1916)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1871)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.content.res.Resources.getLayout(Resources.java:731)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:192)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.view.View.measure(View.java:8313)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.view.View.measure(View.java:8313)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:581)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:365)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.view.View.measure(View.java:8313)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.view.View.measure(View.java:8313)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.view.View.measure(View.java:8313)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.os.Looper.loop(Looper.java:123)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.app.ActivityThread.main(ActivityThread.java:3683)
01-04 12:37:11.299: E/AndroidRuntime(759):  at java.lang.reflect.Method.invokeNative(Native Method)
01-04 12:37:11.299: E/AndroidRuntime(759):  at java.lang.reflect.Method.invoke(Method.java:507)
01-04 12:37:11.299: E/AndroidRuntime(759):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-04 12:37:11.299: E/AndroidRuntime(759):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-04 12:37:11.299: E/AndroidRuntime(759):  at dalvik.system.NativeStart.main(Native Method)
01-04 12:37:11.299: E/AndroidRuntime(759): Caused by: java.io.FileNotFoundException: Corrupt XML binary file
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.content.res.AssetManager.openXmlAssetNative(Native Method)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.content.res.AssetManager.openXmlBlockAsset(AssetManager.java:486)
01-04 12:37:11.299: E/AndroidRuntime(759):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1898)
01-04 12:37:11.299: E/AndroidRuntime(759):  ... 31 more

这是我新添加到项目中的代码。我正在创建自定义微调器样式。

ArrayAdapter<String> dataAdapter3 = new ArrayAdapter<String>

    (this,R.drawable.spinner,R.id.textView2, list3);
                dataAdapter3.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                spinner1.setAdapter(dataAdapter3);

我确定这不是清理项目,或者在log cat中提到图像不存在于hdpi文件夹中。因为如果我将上面的ArrayAdaptor代码替换为我以前的应用程序,那么它运行良好。

1 个答案:

答案 0 :(得分:1)

我认为你在这里犯了错误

(this,R.drawable.spinner,R.id.textView2, list3);

将其替换为

(this,R.id.spinner,R.id.textView2, list3);

如果它不起作用,

使用布局而不是id,

(this,R.layout.yourxmlfile,R.id.textView2, list3);