Android Question java.lang.ClassCastException: android.graphics.drawable.VectorDrawable cannot be cast to android.gra

dragonguy

Active Member
Licensed User
Longtime User
Some of my customer report this error when load the app icon, but i cannot trace which part occur the error. please help me
here is my code
Code: Copy
Sub load_notification_apps_list_data
    ProgressDialogShow2("Please wait",False)
    count_ckb=0
    lbl_count_ckb.Text=count_ckb
    sv2.Clear

    If Starter.notification_apps_list.Size>0 Then
        Dim remove_list As List
        remove_list.Initialize
        Starter.notification_apps_list.Sort(True)
        For Each item As String In Starter.notification_apps_list
            Sleep(0)
            Dim i As Int = Starter.full_apps_list.IndexOf(item)
            If i <> -1 Then
                Starter.full_apps_list.RemoveAt(i)
                Dim s() As String
                s = Regex.Split("#", item)
                Dim bool As Boolean=True
                Dim pm As PackageManager
                Dim b As BitmapDrawable=pm.GetApplicationIcon(s(1))
                Dim d As Bitmap
                d.Initialize3(b.Bitmap)
                Dim c As Bitmap=CreateScaledBitmap(d,96,96,True)
                sv2.Add(CreateListItem1(s(0),s(1),c,bool,sv2.AsView.Width, 50dip), 50dip, s(1))
            Else if i = -1 Then
                remove_list.Add(item)
            End If
        Next
      
        For Each o As String In remove_list
            Dim k As Int = Starter.notification_apps_list.IndexOf(o)
            If  k <> -1 Then
                Starter.notification_apps_list.RemoveAt(k)
            End If
        Next
        Sleep(0)
    End If
    ProgressDialogHide
End Sub

Code: Copy
Sub CreateScaledBitmap(Original As Bitmap, Width As Int, Height As Int, Filter As Boolean) As Bitmap
    Dim jo As JavaObject
    jo.InitializeStatic("android.graphics.Bitmap")
    Return jo.RunMethod("createScaledBitmap", Array (Original, Width, Height, Filter))
End Sub


Code: Copy
Exception java.lang.RuntimeException: java.lang.ClassCastException: android.graphics.drawable.VectorDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
anywheresoftware.b4a.keywords.Common$13.run (Common.java:1679)
android.os.Handler.handleCallback (Handler.java:739)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:135)
android.app.ActivityThread.main (ActivityThread.java:5238)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:931)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:726)
arrow_drop_down
Caused by java.lang.ClassCastException: android.graphics.drawable.VectorDrawable cannot be cast to android.graphics.drawable.BitmapDrawable
com.probitto.my.fnal.main$ResumableSub_load_notification_apps_list_data.resume (main.java:1745)
anywheresoftware.b4a.keywords.Common$13.run (Common.java:1677)
android.os.Handler.handleCallback (Handler.java:739)
android.os.Handler.dispatchMessage (Handler.java:95)
android.os.Looper.loop (Looper.java:135)
android.app.ActivityThread.main (ActivityThread.java:5238)
java.lang.reflect.Method.invoke (Method.java)
java.lang.reflect.Method.invoke (Method.java:372)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:931)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:726)
 
A Vectordrawable cannot be converted into a normal drawable.

android.graphics.drawable.VectorDrawable cannot be cast to android.graphics.drawable.BitmapDrawable

So i guess you are using Vectordrawables?

Please note that vectordrawables are a Android 6 Feature and are not useable on older android devices if you are not using a library wehich support vectordrawables.

See for ex. https://www.b4x.com/android/forum/threads/vectordrawables.68801/#content
Or https://www.b4x.com/android/forum/threads/vectorcompat-morphbutton.71553/
 
Last edited:
Upvote 0
Back
Top