0

我有一个在 API 8 上运行时按预期工作的应用程序,但是当我在任何旧 API 版本上运行它时,它会崩溃:

10-28 12:10:50.755: ERROR/AndroidRuntime(1864): Uncaught handler: thread main exiting due to uncaught exception
10-28 12:10:50.765: ERROR/AndroidRuntime(1864): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nw.caremeter/com.nw.caremeter.CareMeter}: android.view.InflateException: Binary XML file line #35: Error inflating class <unknown>
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.app.ActivityThread.access$2200(ActivityThread.java:126)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.os.Looper.loop(Looper.java:123)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.app.ActivityThread.main(ActivityThread.java:4595)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at java.lang.reflect.Method.invokeNative(Native Method)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at java.lang.reflect.Method.invoke(Method.java:521)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at dalvik.system.NativeStart.main(Native Method)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864): Caused by: android.view.InflateException: Binary XML file line #35: Error inflating class <unknown>
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.view.LayoutInflater.createView(LayoutInflater.java:513)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.app.Activity.setContentView(Activity.java:1629)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at com.nw.caremeter.onCreate(CareMeter.java:48)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     ... 11 more
10-28 12:10:50.765: ERROR/AndroidRuntime(1864): Caused by: java.lang.reflect.InvocationTargetException
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.widget.ImageView.<init>(ImageView.java:105)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at java.lang.reflect.Constructor.constructNative(Native Method)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.view.LayoutInflater.createView(LayoutInflater.java:500)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     ... 22 more
10-28 12:10:50.765: ERROR/AndroidRuntime(1864): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/needle_green.xml from drawable resource ID #0x7f020005
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.content.res.Resources.loadDrawable(Resources.java:1693)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.widget.ImageView.<init>(ImageView.java:115)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     ... 26 more
10-28 12:10:50.765: ERROR/AndroidRuntime(1864): Caused by: java.lang.NullPointerException
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.graphics.drawable.RotateDrawable.inflate(RotateDrawable.java:207)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:788)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     at android.content.res.Resources.loadDrawable(Resources.java:1690)
10-28 12:10:50.765: ERROR/AndroidRuntime(1864):     ... 28 more

API7 失败的原因可能是什么?我的可绘制资源位于 res/drawable 中(我已尝试在 /drawable 中制作副本,但无论 drawable-{hdpi,ldpi} 文件夹如何,问题都仍然存在)。为了完整起见,needle_green.xml:

<?xml version="1.0" encoding="UTF-8"?>
<rotate         xmlns:android="http://schemas.android.com/apk/res/android"
                android:fromDegrees="90"
                android:toDegrees="90"
                android:pivotY="125"
                android:drawable="@drawable/needle_base_green" />

和needle_base_green:

<?xml version="1.0" encoding="UTF-8"?>
<shape          xmlns:android="http://schemas.android.com/apk/res/android"
                android:shape="line">
    <stroke     android:width="2dp"
                android:color="#00ff00" />
</shape>

这几乎是第一个 android 应用程序,所以它可能是令人震惊的微不足道的东西。谢谢你的帮助。

4

2 回答 2

1

Android 找不到 res/drawable/needle_green.xml。你有吗,如果没有,请向我们展示代码。

补充: 尝试使用#FFFF0000(前两个是alpha)作为颜色值

于 2010-10-28T12:29:23.407 回答
0

Android 在 res/drawable 中查找,而不是在 res/drawables 中。

于 2010-10-28T12:26:24.053 回答