Android 1.5 带 xml 绘图
我在一个非常基本的登录屏幕上遇到了问题。据我所知,它确实有一个视图翻转器和相对布局,从 API 1 开始就受支持。出现以下错误:
08-23 13:20:45.567: ERROR/AndroidRuntime(801): Uncaught handler: thread main exiting due to uncaught exception
08-23 13:20:45.577: ERROR/AndroidRuntime(801): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.munzee.android.client/com.munzee.android.client.LogInActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class java.lang.reflect.Constructor
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.os.Looper.loop(Looper.java:123)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.ActivityThread.main(ActivityThread.java:3948)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at java.lang.reflect.Method.invokeNative(Native Method)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at java.lang.reflect.Method.invoke(Method.java:521)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at dalvik.system.NativeStart.main(Native Method)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class java.lang.reflect.Constructor
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.createView(LayoutInflater.java:512)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.rInflate(LayoutInflater.java:620)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.Activity.setContentView(Activity.java:1626)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at com.munzee.android.client.LogInActivity.onCreate(LogInActivity.java:74)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): ... 11 more
08-23 13:20:45.577: ERROR/AndroidRuntime(801): Caused by: java.lang.reflect.InvocationTargetException
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.widget.ImageView.<init>(ImageView.java:103)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at java.lang.reflect.Constructor.constructNative(Native Method)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.createView(LayoutInflater.java:499)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): ... 23 more
08-23 13:20:45.577: ERROR/AndroidRuntime(801): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/title_logo.xml from drawable resource ID #0x7f020056
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.content.res.Resources.loadDrawable(Resources.java:1625)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.widget.ImageView.<init>(ImageView.java:113)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): ... 27 more
08-23 13:20:45.577: ERROR/AndroidRuntime(801): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020058
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.content.res.Resources.getValue(Resources.java:846)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.content.res.Resources.getDrawable(Resources.java:534)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:146)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:749)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:695)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.content.res.Resources.loadDrawable(Resources.java:1622)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): ... 29 more
我查看了另一篇SO帖子(建议将drawable-mdpi删除到drawable文件夹中),这没有帮助。
疯狂的是在我的 R.java 中没有 0x7f020056 或 0x7f020058 的资源 ID...
克里斯。
I am having an issue w/ a pretty basic login screen. It does have a view flipper and relative layouts, both supported since API 1 as far as I can tell. Getting the following error :
08-23 13:20:45.567: ERROR/AndroidRuntime(801): Uncaught handler: thread main exiting due to uncaught exception
08-23 13:20:45.577: ERROR/AndroidRuntime(801): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.munzee.android.client/com.munzee.android.client.LogInActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class java.lang.reflect.Constructor
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.os.Looper.loop(Looper.java:123)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.ActivityThread.main(ActivityThread.java:3948)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at java.lang.reflect.Method.invokeNative(Native Method)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at java.lang.reflect.Method.invoke(Method.java:521)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at dalvik.system.NativeStart.main(Native Method)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class java.lang.reflect.Constructor
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.createView(LayoutInflater.java:512)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.rInflate(LayoutInflater.java:620)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.Activity.setContentView(Activity.java:1626)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at com.munzee.android.client.LogInActivity.onCreate(LogInActivity.java:74)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): ... 11 more
08-23 13:20:45.577: ERROR/AndroidRuntime(801): Caused by: java.lang.reflect.InvocationTargetException
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.widget.ImageView.<init>(ImageView.java:103)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at java.lang.reflect.Constructor.constructNative(Native Method)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.view.LayoutInflater.createView(LayoutInflater.java:499)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): ... 23 more
08-23 13:20:45.577: ERROR/AndroidRuntime(801): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/title_logo.xml from drawable resource ID #0x7f020056
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.content.res.Resources.loadDrawable(Resources.java:1625)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.widget.ImageView.<init>(ImageView.java:113)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): ... 27 more
08-23 13:20:45.577: ERROR/AndroidRuntime(801): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020058
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.content.res.Resources.getValue(Resources.java:846)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.content.res.Resources.getDrawable(Resources.java:534)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:146)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:749)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:695)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): at android.content.res.Resources.loadDrawable(Resources.java:1622)
08-23 13:20:45.577: ERROR/AndroidRuntime(801): ... 29 more
I looked at another SO post (which suggested removing the drawable-mdpi to the drawable folder), which did not help.
What is crazy is in my R.java there is no resource ID for 0x7f020056 or 0x7f020058...
Chris.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,如果您正在构建 1.5,则不允许您拥有可绘制的 mdpi 文件夹。所有与屏幕尺寸相关的资源文件夹修饰符都是在 android 1.6 中引入的(这是第一个支持多种屏幕尺寸的 SDK 版本)。除非您有特定原因不这样做,否则我建议您将应用程序构建为至少 SDK 版本 1.6。市面上有太多不同屏幕尺寸的设备,无法让使用 1.5 构建的设备在所有设备上看起来都很好。如果您必须将项目保持在 1.5,那么您可能只需要删除任何具有屏幕尺寸修改器的文件夹,因此:“drawable-mdpi”、“drawable-hdpi”、“drawable-ldpi”都需要消失,您应该只有“可绘制”
As far as I am aware you are not allowed to have a drawable-mdpi folder if you are building to 1.5. All of the screen size related resource folder modifiers were introduced with android 1.6 (which was the first version of the SDK to support multiple screen sizes). Unless you have a specific reason not to I would suggest building your application to at least SDK version 1.6. There are too many devices with too many different screen sizes out there to make something built with 1.5 look good on all of them. If you must keep your project at 1.5 then you probably just need to get rid of any folders with screen size modifiers so: "drawable-mdpi", "drawable-hdpi", "drawable-ldpi" all need to go away and you should have only "drawable"