Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 903
user2681579 Avatar asked Sep 29 '15 07:09

user2681579


2 Answers

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>

like image 200
Dror Avatar answered Nov 07 '22 17:11

Dror


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

like image 22
Mikeumus Avatar answered Nov 07 '22 16:11

Mikeumus