在手机上但不在平板电脑上运行时出现ResourceNotFoundException [英] ResourceNotFoundException when running on phone but not on tablet

查看:55
本文介绍了在手机上但不在平板电脑上运行时出现ResourceNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在Samsung Note II上运行我的应用程序时,此行出现ResourceNotFoundException

When I try to run my app on my Samsung Note II, I get a ResourceNotFoundException for this line

setContentView(R.layout.activity_main);

但是,当我在模拟器或Samsung Note 10.1上运行该异常时,没有出现此异常.

However, I don't get this exception when I run it on the emulator or my Samsung Note 10.1.

两个都在运行Jellybean,我的xml文件在名为layout-land的文件夹中,并且XML文件在其中.我尝试清理我的项目并重新构建,但是仍然无法正常工作.

Both are running Jellybean and my xml files are in folder called layout-land, and the XML file is in there. I tried cleaning my project and re-building, but it still doesn't work.

有人知道出什么问题了吗?

Does anyone have an idea what's wrong?

让我知道是否可以提供更多信息.谢谢!

Let me know if I can provide any more information. Thanks!

01-27 22:11:32.975: E/AndroidRuntime(28330): FATAL EXCEPTION: main
01-27 22:11:32.975: E/AndroidRuntime(28330): java.lang.RuntimeException: Unable to start activity        ComponentInfo{com.ventusthecorgi.hungrycorgi/com.mypackage.app.MainActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f030003
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.app.ActivityThread.access$600(ActivityThread.java:140)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.os.Handler.dispatchMessage(Handler.java:99)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.os.Looper.loop(Looper.java:137)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.app.ActivityThread.main(ActivityThread.java:4898)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at java.lang.reflect.Method.invokeNative(Native Method)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at java.lang.reflect.Method.invoke(Method.java:511)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at dalvik.system.NativeStart.main(Native Method)
01-27 22:11:32.975: E/AndroidRuntime(28330): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030003
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.content.res.Resources.getValue(Resources.java:1026)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2131)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.content.res.Resources.getLayout(Resources.java:865)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:307)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.app.Activity.setContentView(Activity.java:1916)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at com.ventusthecorgi.hungrycorgi.MainActivity.onCreate(MainActivity.java:22)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.app.Activity.performCreate(Activity.java:5191)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
01-27 22:11:32.975: E/AndroidRuntime(28330):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)

推荐答案

我怀疑您在layout-land目录中仅 有问题的布局文件(根据问题中的内容) .这意味着,如果设备以纵向模式启动,则Android会在layout-port目录中 then layout,而不是 not layout-land中搜索您的布局.我可能是错的,但我的直觉是您的Samsung Note II以纵向模式启动,因此看不到布局文件.

I suspect that you have your problematic layout files only in the layout-land directory (based on what you wrote in the question). This means that if the device is launched in portrait mode, Android will search for your layout in layout-port directory, then layout, but not layout-land. I might be wrong but my hunch is that your Samsung Note II starts in portrait mode and thus doesn't see the layout file.

您必须提供一个后备布局资源.将布局从layout-land复制到layout-port并相应地修改为纵向模式,或者将其作为后备布局复制到layout目录.

You have to provide a fallback layout resource. Either copy the layout from layout-land to layout-port and modify it accordingly for portrait mode or just copy it to layout directory as a fallback layout.

这篇关于在手机上但不在平板电脑上运行时出现ResourceNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆