Error inflating class android.support.design.widget.CoordinatorLayout and ClassNotFoundException: android.support.design.R$styleable-ThrowExceptions

Exception or error:

I am developing an app which have Tab with swipe functionality. I am using Eclipse to develop. I have imported the support design library as Library through Property. During run, i am keep getting this error “Error inflating class android.support.design.widget.CoordinatorLayout“.

  1. First i added android support design.jar and tried, which is not working
  2. I added the class.jar file of support design library through Java build path which is not worked
  3. Finally i imported the support design library as Library using Properties->Android->Add Library this also not working
  4. I am using the Parent theme as “Theme.AppCompat.Light.DarkActionBar

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">

  1. I am extending the AppCompatActivity, see my MainActivity.Java

    package com.example.scrollingtab.activity;

    import android.support.v7.app.AppCompatActivity;
    import android.support.v7.widget.Toolbar;
    import android.widget.Button;
    import com.example.scrollingtab.R;
    
    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    
        private Toolbar toolbar;
        private Button btnSimpleTabs, btnScrollableTabs, btnIconTextTabs, btnIconTabs, btnCustomIconTextTabs;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);
    
            btnSimpleTabs = (Button) findViewById(R.id.btnSimpleTabs);
    
            btnSimpleTabs.setOnClickListener(this);
    
        }
    

Below is the full stack trace:

FATAL EXCEPTION: main
Process: com.example.scrollingtab, PID: 1348
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.scrollingtab/com.example.scrollingtab.activity.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.CoordinatorLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class android.support.design.widget.CoordinatorLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:633)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
at android.view.LayoutInflater.inflate(LayoutInflater.java:482)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:257)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.example.scrollingtab.activity.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:607)
Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/design/R$styleable;
at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:171)
at android.support.design.widget.CoordinatorLayout.<init>(CoordinatorLayout.java:165)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.R$styleable" on path: DexPathList[[zip file "/data/app/com.example.scrollingtab-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
Suppressed: java.lang.ClassNotFoundException: android.support.design.R$styleable
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

I have tried most of the things talked and provided by SO. Still i am not able to trace what is wrong in my program.

Need help to solve this.

Thanks

How to solve:

I got this error while Migrating to AndroidX

To resolve I did:

  1. as suggested by @Mikeumus – and added this to the module’s build.gradle dependencies:

    implementation ‘androidx.coordinatorlayout:coordinatorlayout:latest.version.here’

  2. check in the Layout XML file (the layout that you’re trying to launch with setContentView

if the Layout contains:
<android.support.design.widget.CoordinatorLayout

replace that with : <androidx.coordinatorlayout.widget.CoordinatorLayout

  1. in the same layout file – replace the closing tag

</android.support.design.widget.CoordinatorLayout>

with

</androidx.coordinatorlayout.widget.CoordinatorLayout>

###

For me, this error was resulting from using some androidx libraries but then still having the old coordinate layout in some layout.xml files.

build.gradle:

com.android.support:coordinatorlayout -> androidx.coordinatorlayout:coordinatorlayout:1.0.0-alpha1

If you’re using androidx then maybe this is your problem too.
I had to update the other v7 libraries like Toolbar as well.

See the androidx migration guide here: https://developer.android.com/topic/libraries/support-library/refactor

###

For android studio try to add these dependencies

compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'

###

I found the solution for eclipse

Problem what i faced is R.Java file is not generated under support.design in gen/ folder.

After doing the below steps R.Java file is generated. Main issue is design library is target to 22. Changing to 23 worked.

  1. Import support design library from \sdk\extras\android\support\design to eclipse workspace.

  2. Open project.properties of AppCompat and design Library and target it to 23

  3. Clean Appcompat, design and YourProject.

  4. Run the app

###

Make sure that in your activity set theme AppCompat

<activity
            android:name=".newApp.screens.main.MainActivity"
            android:label="@string/title_activity_main_launch"
            android:theme="@style/AppThemes"></activity>

  <!-- Base application theme. -->
<style name="AppThemes" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">#673AB7</item>
    <item name="colorPrimaryDark">#512DA8</item>
    <item name="colorAccent">#00BCD4</item>
</style>

Leave a Reply

Your email address will not be published. Required fields are marked *