Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError when using large icon in notification

When using a large icon in a notification this error appears and the app crashes:

  06-06 19:53:34.688 25207-25207/com.example.hadi.music E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.hadi.music, PID: 25207
    java.lang.NoClassDefFoundError: Failed resolution of: Landroid/graphics/drawable/Icon;
        at com.example.hadi.music.service.MediaPlayerService.buildNotification(MediaPlayerService.java:90)
        at com.example.hadi.music.service.MediaPlayerService.access$100(MediaPlayerService.java:25)
        at com.example.hadi.music.service.MediaPlayerService$1.onPlay(MediaPlayerService.java:126)
        at android.media.session.MediaSession$CallbackMessageHandler.handleMessage(MediaSession.java:1150)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5221)
        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:899)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "android.graphics.drawable.Icon" on path: DexPathList[[zip file "/data/app/com.example.hadi.music-2/base.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.hadi.music-2/split_lib_slice_9_apk.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)
        at com.example.hadi.music.service.MediaPlayerService.buildNotification(MediaPlayerService.java:90) 
        at com.example.hadi.music.service.MediaPlayerService.access$100(MediaPlayerService.java:25) 
        at com.example.hadi.music.service.MediaPlayerService$1.onPlay(MediaPlayerService.java:126) 
        at android.media.session.MediaSession$CallbackMessageHandler.handleMessage(MediaSession.java:1150) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:135) 
        at android.app.ActivityThread.main(ActivityThread.java:5221) 
        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:899) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 
        Suppressed: java.lang.ClassNotFoundException: android.graphics.drawable.Icon
        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)
                ... 12 more                                                                         

    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

I'm using this method to load the bitmap from url :

.setLargeIcon(Icon.createWithBitmap(utilities.getBitmapFromURL(MusicPlayActivity.base)))


public Bitmap getBitmapFromURL(String strURL) {
        try {
            URL url = new URL(strURL);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setDoInput(true);
            connection.connect();
            InputStream input = connection.getInputStream();
            Bitmap myBitmap = BitmapFactory.decodeStream(input);
            return myBitmap;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

How can fix this problem?

like image 394
Hadi Khezrpor Avatar asked Jun 06 '17 20:06

Hadi Khezrpor


1 Answers

This issue is also reported in google issue tracker here. And according to this answer here, this issue can be solved by updating your libraries to API 27 and using support library v27 or above. Do reply about whether it was solved using this or not.

like image 62
Ashish Bahl Avatar answered Sep 19 '22 14:09

Ashish Bahl