Coma White
Coma White

Reputation: 347

Error inflating class android.widget.ImageButton

I have error when I install my programm on "system/app". When I use "data/app" it's working well. Here is error:

android.view.InflateException: Binary XML file line #19: Error inflating class android.widget.ImageButton
E/AndroidRuntime( 2076):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
E/AndroidRuntime( 2076):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
E/AndroidRuntime( 2076):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime( 2076):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
E/AndroidRuntime( 2076):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 2076):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 2076):    at android.app.ActivityThread.main(ActivityThread.java:3647)
E/AndroidRuntime( 2076):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 2076):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 2076):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 2076):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 2076):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 2076): Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class android.widget.ImageButton
E/AndroidRuntime( 2076):    at android.view.LayoutInflater.createView(LayoutInflater.java:518)
E/AndroidRuntime( 2076):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
E/AndroidRuntime( 2076):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
E/AndroidRuntime( 2076):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
E/AndroidRuntime( 2076):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
E/AndroidRuntime( 2076):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
E/AndroidRuntime( 2076):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
E/AndroidRuntime( 2076):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
E/AndroidRuntime( 2076):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
E/AndroidRuntime( 2076):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
E/AndroidRuntime( 2076):    at android.app.Activity.setContentView(Activity.java:1657)
E/AndroidRuntime( 2076):    at com.pniei.filemanager.Main.onCreate(Main.java:125)
E/AndroidRuntime( 2076):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 2076):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
E/AndroidRuntime( 2076):    ... 11 more
E/AndroidRuntime( 2076): Caused by: java.lang.reflect.InvocationTargetException
E/AndroidRuntime( 2076):    at java.lang.reflect.Constructor.constructNative(Native Method)
E/AndroidRuntime( 2076):    at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
E/AndroidRuntime( 2076):    at android.view.LayoutInflater.createView(LayoutInflater.java:505)
E/AndroidRuntime( 2076):    ... 24 more
E/AndroidRuntime( 2076): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f02000e a=-1 r=0x7f02000e}
E/AndroidRuntime( 2076):    at android.content.res.Resources.loadDrawable(Resources.java:1681)
E/AndroidRuntime( 2076):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
E/AndroidRuntime( 2076):    at android.widget.ImageView.<init>(ImageView.java:118)
E/AndroidRuntime( 2076):    at android.widget.ImageButton.<init>(ImageButton.java:85)
E/AndroidRuntime( 2076):    at android.widget.ImageButton.<init>(ImageButton.java:81)
E/AndroidRuntime( 2076):    ... 27 more

And here is my code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/offWhite">
    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none">
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/offWhite"
            android:gravity="center">

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="6dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="6dp"
                android:src="@drawable/back"
                android:id="@+id/back_button" />
            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="6dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="6dp"
                android:src="@drawable/device_access_sd_storage"
                android:id="@+id/home_button"/>
            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="6dp"
                android:layout_marginRight="2dp"
                android:layout_marginTop="6dp"
                android:src="@drawable/collections_view_as_list"
                android:id="@+id/multiselect_button"/>
            <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                 android:layout_gravity="center_vertical">
                <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:textColor="@color/black"
                        android:textSize="14dp"
                        android:id="@+id/storage_label"/>
                <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:textColor="@color/black"
                        android:textSize="14dp"
                        android:text="путь"
                        android:id="@+id/path_label"/>
                <TextView
                        android:id="@+id/detail_label"
                        android:textColor="@color/brightRed"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:textSize="14px"
                        android:gravity="center"/>
                </LinearLayout>

        </LinearLayout>
    </HorizontalScrollView>
</LinearLayout>

I have no ideas, what's it can be. I use Android 2.3 and IntelliJ IDEA Community Edition 12.0.4.

Upvotes: 2

Views: 7338

Answers (4)

nando
nando

Reputation: 181

I hope my answer can still help someone. I had the same problem in Android 6.0, the error is because it cannot inflate the view due to a problem in the ImageButton, in its attributes android: background or android: src since in these you can refer to drawable, where the problem is triggered, since from Android Studio 1.4 the folders for design elements (v21), (v24) are handled , etc, and it is very common not to put the images or backgrounds in the drawable folders correctly.

res
--- drawable
--- drawable(-v21)
--- drawable(-v24)

This problem can occur in any object that uses the android: background or android: src attributes referring to the drawable folder.

Solution:
In the ImageButtons of the example, in its attributes android: src, it refers to back and device_access_sd_storage

<ImageButtons
.....
android:src="@drawable/back"
.....
<ImageButtons
.....
android:src="@drawable/device_access_sd_storage"
.....

We look for these elements back and device_access_sd_storage in these directories drawable (-v21), drawable (-v24), ....

res
--- drawable(-v21)
--- drawable(-v24)

then we copy it or move it to this directory drawable

res
--- drawable\

We run the APP again and the error would be resolved.

Upvotes: 0

whalemare
whalemare

Reputation: 1326

In your ImageButton need replace

android:src="@drawable/back" to app:srcCompat="@drawable/back"

and add to your Gradle file

defaultConfig { vectorDrawables.useSupportLibrary = true }

Upvotes: 2

Hardik Nadiyapara
Hardik Nadiyapara

Reputation: 2436

in above xmlfile I didn't find xmlns:tools="http://schemas.android.com/tools" on your root layout if not try to add this line.

Upvotes: 0

Neoh
Neoh

Reputation: 16164

Are you sure back, device_access_sd_storage, and collections_view_as_list are all png images in your drawable folder? It complains that one or more of these ids are invalid.

Upvotes: 0

Related Questions