1

I get the following exception when I launch my activity:

05-28 13:34:09.399: E/AndroidRuntime(502): FATAL EXCEPTION: main
05-28 13:34:09.399: E/AndroidRuntime(502): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nykkos.personalize/com.nykkos.personalize.screens.SummaryCostScreen}: android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.ImageView
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.os.Looper.loop(Looper.java:137)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.app.ActivityThread.main(ActivityThread.java:4424)
05-28 13:34:09.399: E/AndroidRuntime(502):  at java.lang.reflect.Method.invokeNative(Native Method)
05-28 13:34:09.399: E/AndroidRuntime(502):  at java.lang.reflect.Method.invoke(Method.java:511)
05-28 13:34:09.399: E/AndroidRuntime(502):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-28 13:34:09.399: E/AndroidRuntime(502):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-28 13:34:09.399: E/AndroidRuntime(502):  at dalvik.system.NativeStart.main(Native Method)
05-28 13:34:09.399: E/AndroidRuntime(502): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.ImageView
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.view.LayoutInflater.createView(LayoutInflater.java:606)
05-28 13:34:09.399: E/AndroidRuntime(502):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.view.LayoutInflater.parseInclude(LayoutInflater.java:823)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:729)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-28 13:34:09.399: E/AndroidRuntime(502):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.app.Activity.setContentView(Activity.java:1835)
05-28 13:34:09.399: E/AndroidRuntime(502):  at com.nykkos.personalize.screens.SummaryCostScreen.onCreate(SummaryCostScreen.java:37)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.app.Activity.performCreate(Activity.java:4465)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-28 13:34:09.399: E/AndroidRuntime(502):  ... 11 more
05-28 13:34:09.399: E/AndroidRuntime(502): Caused by: java.lang.reflect.InvocationTargetException
05-28 13:34:09.399: E/AndroidRuntime(502):  at java.lang.reflect.Constructor.constructNative(Native Method)
05-28 13:34:09.399: E/AndroidRuntime(502):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.view.LayoutInflater.createView(LayoutInflater.java:586)
05-28 13:34:09.399: E/AndroidRuntime(502):  ... 26 more
05-28 13:34:09.399: E/AndroidRuntime(502): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f020000 a=-1 r=0x7f020000}
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.content.res.Resources.loadDrawable(Resources.java:1899)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.widget.ImageView.<init>(ImageView.java:119)
05-28 13:34:09.399: E/AndroidRuntime(502):  at android.widget.ImageView.<init>(ImageView.java:109)
05-28 13:34:09.399: E/AndroidRuntime(502):  ... 29 more
05-28 13:34:09.549: W/ActivityManager(77):   Force finishing activity com.nykkos.personalize/.screens.SummaryCostScreen

THe error in activity is from:

setContentView(R.layout.summarycost_layout);

The xml file summarycost_layout is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <include
    android:id="@+id/includeTitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    layout="@layout/titlebar_layout" />

    <LinearLayout
    android:id="@+id/layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:orientation="horizontal" >

    <ListView
        android:id="@+id/summaryCostListview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white" >
    </ListView>
    </LinearLayout>

    <LinearLayout
    android:id="@+id/layoutTotal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:gravity="center"
    android:orientation="horizontal"
    android:paddingLeft="10dp" >

    <TextView
        android:id="@+id/txtTotal"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center_vertical"
        android:text="Total Cost(0/0)"
        android:textColor="@color/blue"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/totalValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="$0"
        android:textColor="@color/blue" />

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="invisible" />
    </LinearLayout>

    <LinearLayout
    android:id="@+id/layout"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/buttonCancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/button_bg"
        android:text="@string/cancel"
        android:textColor="@android:color/white" />

    <Button
        android:id="@+id/buttonAll"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/button_bg"
        android:text="@string/select_all"
        android:textColor="@android:color/white" />

    <Button
        android:id="@+id/buttonAccept"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/button_bg"
        android:text="@string/accept"
        android:textColor="@android:color/white" />
    </LinearLayout>

</LinearLayout>

and the titlebar_layout referred in the above xml file is:

<?xml version="1.0" encoding="utf-8"?>

<ImageView
    android:id="@+id/imgBack"
    android:layout_width="32dp"
    android:layout_height="32dp"
    android:onClick="onBackClick"
    android:src="@drawable/arrow_back" />

<TextView
    android:id="@+id/txtTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:gravity="center_horizontal"
    android:textColor="@android:color/white" />

<ImageView
    android:id="@+id/imgForward"
    android:layout_width="32dp"
    android:layout_height="32dp"
    android:onClick="onForwardClick"
    android:src="@drawable/arrow_for" />

It seems , the issue is from <ImageView of the titlebar_layout.

I'm a little bit lost with where to look for the cause of the exception. I even don't know if this is really an issue in this layout file etc.

How would you go about finding the cause for this issue?

Any help is appreciated.

10
  • Clean your project (e.g., Project > Clean in Eclipse), then try it again and see if it helps. Commented May 28, 2013 at 9:33
  • tried many a times, no luck Commented May 28, 2013 at 9:50
  • Look at your R.java file and see what 0x7f020000 maps to. Commented May 28, 2013 at 9:51
  • it maps to arrow_back Commented May 28, 2013 at 9:53
  • Is that the only occurrence of 0x7f020000 in R.java? Do you have only one R.java, or do you have others (e.g., for Android library projects that you are importing)? Commented May 28, 2013 at 9:53

1 Answer 1

1

I have experienced the exact issue advised by the OP in the past and @shoe rat has alluded to the correct answer above in his comments.

I'm guessing your PNG drawables are not located in the base 'drawable' folder where Android can find a match on the device or emulator you are testing with. You have probably inadvertently copied your arrow_back and button_bg drawables into for example, drawable-large and drawable-xlarge but are testing on a device or emulator that is say small (320x280). In my example the matching rules can't find a match for the small screen size hence the android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path) error results.

So for a quick test, copy your arrow_back and button_bg drawables (plus any others you have) to the drawable folder and it should compile and run without error because the drawables in the drawable folder will always be found and used as a fallback. Then of course ensure you create appropriate sized drawables for each screen size to suit all screen variations and read the 'How Android Finds the Best-matching Resource' to better understand the drawable matching process in Android.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.