views:

51

answers:

2

I have an app that works as intended when run on API 8, but when I run it on any older API version, it crashes with:

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

What reasons might there be for this failing on API7? My drawable resources are in res/drawable (I've tried making copies in /drawable, and the problem persists regardless of drawable-{hdpi,ldpi} folders). For the sake of completeness, 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" />

And 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>

This is pretty much a first android app, so it's likely something shockingly trivial. Thanks for any help.

A: 

Android looks in res/drawable, not in res/drawables.

Maurits Rijk
Sorry, those were (all!) typos in my post.
Estel
+1  A: 

Android can't find res/drawable/needle_green.xml. Do you have it, if no show us the code.

added: Try to use #FFFF0000 (first two is alpha) as color value

Orsol
It gave nullpointererrors for both depending on which were referenced first. Here's the green version is identical to the red version (the _base_ version is similarly identical)<?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" />
Estel
I've edited my answer
Orsol
No luck, I'm afraid. Same error.
Estel
"rotate" is drawable?
Orsol
Presumably. It all works fine on API 8.
Estel
I tried your code on both versions of API and all works fine for me. Try to create project with minimal code that reproduces the bug and post it here.
Orsol
I've uploaded a minimal project that reproduces this (for me) here: http://estel.uwcs.co.uk/TestProject.zip
Estel
What do you want to achieve with rotate? It's definitely not a drawable resource (all of them you can find here http://developer.android.com/guide/topics/resources/drawable-resource.html) and this is strange that this code works for API8.
Orsol
The rotate was used in order to get a vertical line, which seemed more efficient than using a bitmap to display a line which thereafter would have to have multiple rotations applied to it. I fixed it by moving to a bitmap instead.
Estel