0

I downloaded icons for navigation drawer items at here
And I changed my drawer item icons. And then, I tried to run my app.
But, my app is not working. It was fine before change icons.

I just moved xml files of icons to drawable-v21 folder.

Here is the message.

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.hsk.hallymexam, PID: 11979
    java.lang.RuntimeException: Unable to start activity ComponentInfo

    {com.hsk.hallymexam/com.hsk.hallymexam.MainActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class android.support.design.widget.NavigationView
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2436)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495)
    at android.app.ActivityThread.access$900(ActivityThread.java:170)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5635)
    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:1291)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
    at dalvik.system.NativeStart.main(Native Method)
    Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class android.support.design.widget.NavigationView
    at android.view.LayoutInflater.createView(LayoutInflater.java:626)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
    at com.hsk.hallymexam.MainActivity.onCreate(MainActivity.java:42)
    at android.app.Activity.performCreate(Activity.java:5580)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495) 
    at android.app.ActivityThread.access$900(ActivityThread.java:170) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:146) 
    at android.app.ActivityThread.main(ActivityThread.java:5635) 
    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:1291) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 
    at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at android.view.LayoutInflater.createView(LayoutInflater.java:600)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
    at com.hsk.hallymexam.MainActivity.onCreate(MainActivity.java:42) 
    at android.app.Activity.performCreate(Activity.java:5580) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495) 
    at android.app.ActivityThread.access$900(ActivityThread.java:170) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:146) 
    at android.app.ActivityThread.main(ActivityThread.java:5635) 
    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:1291) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 
    at dalvik.system.NativeStart.main(Native Method) 
    Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f020050
    at android.content.res.Resources.getValue(Resources.java:2326)
    at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:321)
    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:197)
    at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:192)
    at android.support.v7.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:421)
    at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.prepareMenuItems(NavigationMenuPresenter.java:495)
    at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.update(NavigationMenuPresenter.java:436)
    at android.support.design.internal.NavigationMenuPresenter.updateMenuView(NavigationMenuPresenter.java:112)
    at android.support.design.widget.NavigationView.inflateMenu(NavigationView.java:245)
    at android.support.design.widget.NavigationView.<init>(NavigationView.java:169)
    at android.support.design.widget.NavigationView.<init>(NavigationView.java:95)
    at java.lang.reflect.Constructor.constructNative(Native Method) 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 
    at android.view.LayoutInflater.createView(LayoutInflater.java:600) 
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702) 
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:498) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:398) 
    at android.view.LayoutInflater.inflate(LayoutInflater.java:354) 
    at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280) 
    at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
    at com.hsk.hallymexam.MainActivity.onCreate(MainActivity.java:42) 
    at android.app.Activity.performCreate(Activity.java:5580) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495) 
    at android.app.ActivityThread.access$900(ActivityThread.java:170) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:146) 
    at android.app.ActivityThread.main(ActivityThread.java:5635) 
    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:1291) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107) 
    at dalvik.system.NativeStart.main(Native Method)

Did I do something wrong?

Janki Gadhiya
  • 4,492
  • 2
  • 29
  • 59
Chris
  • 392
  • 4
  • 16
  • you are using vector drawables (xml files) for icons..right? – Onkar Nene Jul 06 '16 at 07:39
  • Could you clarify your question? There might be multiple reasons. Maybe its about the Android version your device is running. Vector drawables (if you used such drawables) are not supported directly on older Androids (but there is a support library for that). Further, you state that you placed your icons within the 21 folder, making them available only on API level 21 devices. Is your device running on level 21? – Baschi Jul 06 '16 at 07:58
  • @OnkarNene Yes right. – Chris Jul 06 '16 at 08:08
  • @Baschi you are right. it was API level problem. – Chris Jul 06 '16 at 08:11

4 Answers4

0

You need to put all drawer icon into drawable-hdpi,drawable-mdpi,drawable-xhdpi drawable-xxhdpi and drawable-xxxhdpi folder

Linh
  • 57,942
  • 23
  • 262
  • 279
0

There are many reasons for this exception:

  1. Icon size too large (in pixels) Solution : All your drawables used in navigation drawer and other icons should be atmost of 48*48 pixel size.

  2. Improper reference to drawable Solution : First copy the image (which follows solution-1) and then in android studio, paste it in the drawable root folder.

  3. Improper support of SVG Solution : follow this link

All your XML drawables should be stored in drawables root folder and not in size specific sub folders for better results.

If you are using SVG files, then follow the link i mentioned above, copying XML files to another API specific folder directly will only increase your problem

Community
  • 1
  • 1
Mohammed Atif
  • 4,383
  • 7
  • 28
  • 57
0

first of all, as other people suggesting don't place your icons in mipmap folder. It is a specific folder only for application icon. Place all you icons in drawable folders.

Second, check your drawable folder. If your icons only placed in drawable-v21 then you have a problem, because drawable-v21 used only for devices with api level >= 21. Just replace them to drawable folder

Third, if you using vector graphics and want to support devices with api level < 21, you need to enable supporting of vector drawables. More info here

Michael Spitsin
  • 2,539
  • 2
  • 19
  • 29
-1

I assume that you are using Android Studio IDE

1) If you are using png / jpg icons then put your icons in respective mipmap folder i.e, mipmap-hdpi, mipmap-xhdpi, etc. & then reference it as @mipmap/YOUR_ICON_NAME

2) If you are using XML (vector drawables) files for icons then put your all xml(vector drawables) files in drawable folder instead of drawable-v21 and then reference it as @drawable/YOUR_XML_FILE_NAME

Hope it will help :)

Onkar Nene
  • 1,359
  • 1
  • 17
  • 23