在使用gson.fromJson 把字符串转成ResolveInfo对象时
抛出
java.lang.RuntimeException: Unable to start activity ComponentInfo{sk.carlauncher/sk.carlauncher.ui.MainActivity}: java.lang.RuntimeException: Failed to invoke protected java.lang.ClassLoader() with no args
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2793)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2864)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1567)
Caused by: java.lang.InstantiationException: Can't instantiate abstract class java.lang.ClassLoader
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at com.google.gson.internal.ConstructorConstructor$3.construct(ConstructorConstructor.java:108)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:210)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
这样的错误,单看错误是ClassLoader这个类出的问题,对此类没有研究过。只能stackoverflow
The way I fixed this issue was to create my own object with the necessary data. It saves space and fixes this issue. The issue arises when you try to serialize android objects.
一个回答者说是解决这个问题的方法是创建我自己需要的对象。后半句是说引起这个问题的原因是你试着序列化一个android的对象。
这正是我的问题所在,ResolveInfo是系统类,那我自定义一个实体类,在里面引用ResolveInfo,这样问题就解决了。
附上地址