3

I am getting this error:

Binary XML file line #45: Error inflating class ImageButton

I just dont understand why. It only happens on some devices, not all. On the same emulator its working with api 21, but when using api 19 it just crashes. I tried to find solutions like updating tools, removing libraries and stuff like that but it didnt work. How can I fix this?

FATAL EXCEPTION: main
Process: com.company.example, PID: 24772
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company.example/com.company.example.MainActivity}: android.view.InflateException: Binary XML file line #45: Error inflating class ImageButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #45: Error inflating class ImageButton
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:714)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:756)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:840)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:759)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.company.example.MainActivity.onCreate(MainActivity.java:70)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
at android.app.ActivityThread.access$800(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5017) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
at dalvik.system.NativeStart.main(Native Method) 
Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f020088 a=-1 r=0x7f020088}
at android.content.res.Resources.loadDrawable(Resources.java:2073)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.view.View.<init>(View.java:3554)
at android.widget.ImageView.<init>(ImageView.java:123)
at android.widget.ImageButton.<init>(ImageButton.java:87)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:57)
at android.support.v7.widget.AppCompatImageButton.<init>(AppCompatImageButton.java:53)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:118)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:756) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) 
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:840) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746) 
at android.view.LayoutInflater.rInflate(LayoutInflater.java:759) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
at com.company.example.MainActivity.onCreate(MainActivity.java:70) 
at android.app.Activity.performCreate(Activity.java:5231) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
at android.app.ActivityThread.access$800(ActivityThread.java:135) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:136) 
at android.app.ActivityThread.main(ActivityThread.java:5017) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
at dalvik.system.NativeStart.main(Native Method) 

My activity_main.xml a.k.a. my layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.company.example.MainActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:id="@+id/view">
<include
android:layout_height="wrap_content"
android:layout_width="match_parent"
layout="@layout/toolbar_layout"
app:navigationIcon="?attr/homeAsUpIndicator"/>

<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tabLayout"
app:tabMode="fixed"
app:tabGravity="fill"
app:tabIndicatorColor="@color/colorWhite"
></android.support.design.widget.TabLayout>
</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/viewPager"
android:nestedScrollingEnabled="false"
android:layout_below="@+id/view"
></android.support.v4.view.ViewPager>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/multiple_actions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:visibility="gone"
fab:fab_addButtonColorNormal="@color/colorPrimary"
fab:fab_addButtonColorPressed="@color/colorPrimaryDark"
fab:fab_addButtonPlusIconColor="@color/colorWhite"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp">

<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:theme="@style/MyRandomTheme"
fab:fab_colorNormal="@color/colorPrimary"
fab:fab_icon="@drawable/ic_today_24dp"
fab:fab_size="mini"
fab:fab_colorPressed="@color/colorPrimary"
android:onClick="getWeek"/>

<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/colorPrimary"
fab:fab_colorPressed="@color/colorPrimaryDark"
fab:fab_icon="@drawable/ic_person_24dp"
fab:fab_size="mini"
android:onClick="getLeerling"/>

<com.getbase.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
fab:fab_colorNormal="@color/colorPrimary"
fab:fab_colorPressed="@color/colorPrimaryDark"
fab:fab_icon="@drawable/ic_settings_24dp"
fab:fab_size="mini"
android:onClick="getSettings"/>

</com.getbase.floatingactionbutton.FloatingActionsMenu>

<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end|right"
android:src="@drawable/ic_cached_white_24dp"
android:layout_marginRight="35dp"
android:layout_marginEnd="35dp"
android:layout_marginBottom="60dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:onClick="restartApp"/><!--32 dp bottom-->
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/banner_ad_unit_id" />
</RelativeLayout>
</RelativeLayout>

activity is too big to post, so well ... eh ... ill post the oncreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    //setTheme(R.style.MyRandomTheme);
    main = this;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    if(getIntent()!=null && getIntent().hasExtra(getPackageName())){notificationManager.cancelAll(); }
    toolbar = (Toolbar) findViewById(R.id.toolBar);
    setSupportActionBar(toolbar);
    TextView title = (TextView) findViewById(R.id.ToolbarIconsTextview);
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int width = size.x;
    if (width <= 520) {title.setTextSize(14);}
    final SharedPreferences prefers = this.getSharedPreferences("com.devwild.zermelo", Context.MODE_PRIVATE);
    //prefers.edit().putBoolean("premium", false).apply();
    int PrimaryColor = prefers.getInt("PrimaryColor", 0);
    final TabLayout tablayout = (TabLayout) findViewById(R.id.tabLayout);
    FloatingActionButton Fab = (FloatingActionButton) findViewById(R.id.fab);
    if (PrimaryColor != 0) {
        if (getSupportActionBar() != null)
            getSupportActionBar().setBackgroundDrawable(new ColorDrawable(PrimaryColor));
        tablayout.setBackgroundColor(PrimaryColor);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(CircleView.shiftColorDown(PrimaryColor));
            getWindow().setNavigationBarColor(PrimaryColor);
            ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("Zermelo", null, PrimaryColor); //replace icon today with zermelo
            (this).setTaskDescription(taskDescription);
        }
        Fab.setRippleColor(PrimaryColor);
        Fab.setBackgroundTintList(ColorStateList.valueOf(PrimaryColor));
    }
    if (Build.VERSION.SDK_INT <= 17) {
        try {
            FloatingActionsMenu multiple_actions = (FloatingActionsMenu) findViewById(R.id.multiple_actions);
            multiple_actions.setVisibility(View.VISIBLE);
            GridLayout toolBar = (GridLayout) findViewById(R.id.ToolbarIcons);
            toolBar.setVisibility(View.GONE);
            TextView toolbarIconsTextview = (TextView) findViewById(R.id.ToolbarIconsTextview);
            toolbarIconsTextview.setVisibility(View.GONE);
        } catch (NullPointerException e) {e.printStackTrace();}
    }
    tabLayout = (TabLayout) findViewById(R.id.tabLayout);
    viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
    SharedPreferences prefs = this.getSharedPreferences("com.devwild.zermelo", Context.MODE_PRIVATE);
    String authcode = prefs.getString("Authcode", "");
    String school = prefs.getString("School", "");
    if (authcode.equalsIgnoreCase(null) || authcode.equalsIgnoreCase("") || school.equalsIgnoreCase(null) || school.equalsIgnoreCase("")) {
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setVisibility(View.GONE);
        viewPagerAdapter.addFragments(new LoginFragment(), "VR");
        TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout);
        tabLayout.setVisibility(View.GONE);
        GridLayout toolBar = (GridLayout) findViewById(R.id.ToolbarIcons);
        toolBar.setVisibility(View.GONE);
        TextView toolbarIconsTextview = (TextView) findViewById(R.id.ToolbarIconsTextview);
        toolbarIconsTextview.setVisibility(View.GONE);
    } else {
        viewPagerAdapter.addFragments(new Maandag(), "MA");
        viewPagerAdapter.addFragments(new Dinsdag(), "DI");
        viewPagerAdapter.addFragments(new Woensdag(), "WO");
        viewPagerAdapter.addFragments(new Donderdag(), "DO");
        viewPagerAdapter.addFragments(new Vrijdag(), "VR");
    }
    viewPager.setAdapter(viewPagerAdapter);
    tabLayout.setupWithViewPager(viewPager);
    viewPager.setOffscreenPageLimit(5);
    bp = new BillingProcessor(this, LICENSE_KEY, MERCHANT_ID, new BillingProcessor.IBillingHandler() {
        @Override
        public void onProductPurchased(String productId, TransactionDetails details) {
            prefers.edit().putBoolean("premium", true).apply();
            Toast.makeText(getApplicationContext(), "Aankoop voltooid! Enorm bedankt! Geniet van de app!", Toast.LENGTH_LONG).show();
        }
        @Override
        public void onBillingError(int errorCode, Throwable error) {}
        @Override
        public void onBillingInitialized() {
            if (prefers.contains("premium")) {
                if (prefers.getBoolean("premium", false) == true) {}
                else {
                    bp.loadOwnedPurchasesFromGoogle();
                    boolean isItPurchased = bp.isPurchased("premium");
                    if (isItPurchased == true) {prefers.edit().putBoolean("premium", true).apply();}
                }
            }
            else {
                bp.loadOwnedPurchasesFromGoogle();
                boolean isItPurchased = bp.isPurchased("premium");
                if (isItPurchased == true) {prefers.edit().putBoolean("premium", true).apply();}
            }
        }
        @Override
        public void onPurchaseHistoryRestored() {}
    });

    notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    if(getIntent()!=null && getIntent().hasExtra(getPackageName())){notificationManager.cancel(NOTIFICATION_ID);}
    Calendar c = Calendar.getInstance();
    int currentDay = c.get(Calendar.DAY_OF_WEEK);
    Boolean notifications = prefs.getBoolean("Notificaties", false);
    if (prefs.contains("Notificaties")) {
        if (notifications == true) {
            switch (currentDay) {
                case 1:viewPager.setCurrentItem(0, true);break;
                case 2:viewPager.setCurrentItem(0, true);prefers.edit().putString("NotificationDay", "Monday").apply();notificationThread.start();break;
                case 3:viewPager.setCurrentItem(1, true);prefers.edit().putString("NotificationDay", "Tuesday").apply();notificationThread.start();break;
                case 4:viewPager.setCurrentItem(2, true);prefers.edit().putString("NotificationDay", "Wednesday").apply();notificationThread.start();break;
                case 5:viewPager.setCurrentItem(3, true);prefers.edit().putString("NotificationDay", "Thursday").apply();notificationThread.start();break;
                case 6:viewPager.setCurrentItem(4, true);prefers.edit().putString("NotificationDay", "Friday").apply();notificationThread.start();break;
                case 7:viewPager.setCurrentItem(0, true);break;
                default:viewPager.setCurrentItem(0, true);break;
            }
        }
        else {
            switch (currentDay) {
                case 1:viewPager.setCurrentItem(0, true);break;
                case 2:viewPager.setCurrentItem(0, true);break;
                case 3:viewPager.setCurrentItem(1, true);break;
                case 4:viewPager.setCurrentItem(2, true);break;
                case 5:viewPager.setCurrentItem(3, true);break;
                case 6:viewPager.setCurrentItem(4, true);break;
                case 7:viewPager.setCurrentItem(0, true);break;
                default:viewPager.setCurrentItem(0, true);break;
            }
        }
    }
    else {
        switch (currentDay) {
            case 1:viewPager.setCurrentItem(0, true);break;
            case 2:viewPager.setCurrentItem(0, true);break;
            case 3:viewPager.setCurrentItem(1, true);break;
            case 4:viewPager.setCurrentItem(2, true);break;
            case 5:viewPager.setCurrentItem(3, true);break;
            case 6:viewPager.setCurrentItem(4, true);break;
            case 7:viewPager.setCurrentItem(0, true);break;
            default:viewPager.setCurrentItem(0, true);break;
        }
    }

    if (prefs.contains("CompletedIntro")) {
        if (prefs.getBoolean("CompletedIntro", false)) {
        }
        else {
            finish();
            Intent i = new Intent(this, Intro.class);
            startActivity(i);
        }

    }
    else if (!prefs.contains("CompletedIntro")) {
        finish();
        Intent i = new Intent(this, Intro.class);
        startActivity(i);
    }

}
13
  • Are you using some kind of vector drawable(svg)? Commented Jul 19, 2016 at 19:47
  • Is the image for your image button in a versioned folder? stackoverflow.com/questions/4512981/… Commented Jul 19, 2016 at 19:56
  • @AdamForbis I don't know why there should be an image button. I never made one, and when I searched the whole project it was never really used, so its a bit stranged. Commented Jul 19, 2016 at 19:57
  • You may need to post the code for your activity, according to the logcat you have an ImageButton. Commented Jul 19, 2016 at 19:59
  • Your layout xml would also be useful. Commented Jul 19, 2016 at 20:03

2 Answers 2

1

To clear the question where the ImageButton is coming from:

The FloatingActionButton class is extending ImageButton class.


The error is the following:

Resource is not a Drawable.

So somewhere in one of your FloatingActionButtons you used a drawable that contains errors or is not actually an image.

Check that.

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

1 Comment

It had nothing to do with the FloatingActionButton
1

Appearantly, an icon in the toolbar that I include in the activity_main.xml was corrupt

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.