9

Hi I am using NavigationView but I am getting error, below is my xml, I have already included android support and v7 library

project.properties as I am not using Android studio

target=android-22
android.library.reference.1=../android-support-v7-appcompat
android.library.reference.2=../design


<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.toxic.apps.kodi" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/primary"
        android:minHeight="?attr/actionBarSize" />

    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/navigation"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/drawer_header"
    app:itemTextColor="@color/primary"
    app:menu="@menu/drawer" />

</android.support.v4.widget.DrawerLayout>

and below is my stacktrace

06-21 06:24:12.799: E/AndroidRuntime(4913): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.toxic.apps.kodi/com.toxic.apps.kodi.Activities.MainActivity}: android.view.InflateException: Binary XML file line #30: Error inflating class android.support.design.widget.NavigationView
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.app.ActivityThread.access$800(ActivityThread.java:144)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.os.Handler.dispatchMessage(Handler.java:102)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.os.Looper.loop(Looper.java:135)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.app.ActivityThread.main(ActivityThread.java:5221)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at java.lang.reflect.Method.invoke(Native Method)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at java.lang.reflect.Method.invoke(Method.java:372)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
06-21 06:24:12.799: E/AndroidRuntime(4913): Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class android.support.design.widget.NavigationView
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.view.LayoutInflater.createView(LayoutInflater.java:633)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at com.toxic.apps.kodi.Activities.AbstractBaseActivity.setContentView(AbstractBaseActivity.java:33)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at com.toxic.apps.kodi.Activities.MainActivity.onCreate(MainActivity.java:35)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.app.Activity.performCreate(Activity.java:5933)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
06-21 06:24:12.799: E/AndroidRuntime(4913):     ... 10 more
06-21 06:24:12.799: E/AndroidRuntime(4913): Caused by: java.lang.reflect.InvocationTargetException
06-21 06:24:12.799: E/AndroidRuntime(4913):     at java.lang.reflect.Constructor.newInstance(Native Method)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.view.LayoutInflater.createView(LayoutInflater.java:607)
06-21 06:24:12.799: E/AndroidRuntime(4913):     ... 22 more
06-21 06:24:12.799: E/AndroidRuntime(4913): Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/design/R$styleable;
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.support.design.internal.ScrimInsetsFrameLayout.<init>(ScrimInsetsFrameLayout.java:54)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.support.design.widget.NavigationView.<init>(NavigationView.java:92)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at android.support.design.widget.NavigationView.<init>(NavigationView.java:88)
06-21 06:24:12.799: E/AndroidRuntime(4913):     ... 25 more
06-21 06:24:12.799: E/AndroidRuntime(4913): Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.R$styleable" on path: DexPathList[[zip file "/data/app/com.toxic.apps.kodi-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
06-21 06:24:12.799: E/AndroidRuntime(4913):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
06-21 06:24:12.799: E/AndroidRuntime(4913):     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
06-21 06:24:12.799: E/AndroidRuntime(4913):     ... 28 more
06-21 06:24:12.799: E/AndroidRuntime(4913):     Suppressed: java.lang.ClassNotFoundException: android.support.design.R$styleable
06-21 06:24:12.799: E/AndroidRuntime(4913):         at java.lang.Class.classForName(Native Method)
06-21 06:24:12.799: E/AndroidRuntime(4913):         at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
06-21 06:24:12.799: E/AndroidRuntime(4913):         at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
06-21 06:24:12.799: E/AndroidRuntime(4913):         at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
06-21 06:24:12.799: E/AndroidRuntime(4913):         ... 29 more
06-21 06:24:12.799: E/AndroidRuntime(4913):     Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
rds
  • 26,253
  • 19
  • 107
  • 134
ingsaurabh
  • 15,249
  • 7
  • 52
  • 81
  • Have you created the menu item – Psypher Jun 21 '15 at 11:32
  • post you dependencies from gradle file seems that you've missed something – Oleg Osipenko Jun 21 '15 at 11:33
  • Yes app:menu="@menu/drawer" – ingsaurabh Jun 21 '15 at 11:34
  • @OlegOsipenko updated the project.properties – ingsaurabh Jun 21 '15 at 11:37
  • 1
    If you're building with eclipse, check if the resources of the design library are correctly loaded and the R file is generated accordingly. Maybe, a clean project helps. – Denis Loh Jun 21 '15 at 12:03
  • @DenisLoh I checked R file for design library is not generated, it doesnt gives me any error and when I comment out NavigationView from xml evrything runs fine – ingsaurabh Jun 21 '15 at 12:06
  • According to googles blog: "Note that as the Design library depends on the Support v4 and AppCompat Support Libraries, those will be included automatically when you add the Design library dependency." you are probably missing the support v4 library. Can you please update your dependencies, if you have that included? – Denis Loh Jun 21 '15 at 12:22
  • @DenisLoh As I have added Support v7 library so v4 library is already added by default also as per your suggestion I explicitly added v4 but same crash – ingsaurabh Jun 21 '15 at 12:24
  • Are you able to solve this crash, I am getting same crash when using support design library on eclipse. Please guide. – Dory Jun 25 '15 at 07:06
  • @Dory check I have posted the answer – ingsaurabh Jun 25 '15 at 07:43

3 Answers3

9

Ok finally I solved the problem using Denis Loh suggestion. Key to solve this problem is check the R file of all the included libraries, when this crash happens design library R is not generated and hence not shown in gen folder of your project.

But eclipse will not show you problem why it is not generated(God knows how eclipse work)

So in order to generate R file of design folder

In project.properties of design library set target to 21 or highest available

Clean v7 , design and your project run & enjoy

ingsaurabh
  • 15,249
  • 7
  • 52
  • 81
  • This pointed me in the right direction, although if this doesn't help anyone try to delete the 'build' folder in the root of your project's directory and then 'Build > Rebuild Project' – wzlr May 12 '21 at 08:56
1

You can import androidSupportDesign from \sdk\extras\android\support\design and tick "isLibrary", then you import appcombat_v7(lib) to androidSupportDesign. Final you import to your project and clean build all! I hope it can help

All project build with api > 21

you!

Thientvse
  • 1,753
  • 1
  • 14
  • 23
0

How I solve this problem is to run './gradlew clean' first, then try to compile the code with './gradlew installDebug'.

I guess the problem is due to the old R file still remain the same, and the compiler can't find resource related to CoordinatorLayout within the old R file.

May this help.

Anthonyeef
  • 2,595
  • 1
  • 27
  • 25