gson 字符串转换android对象报错 Can't instantiate abstract class java.lang.ClassLoader

在使用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,这样问题就解决了。


附上地址

https://stackoverflow.com/questions/24585333/android-runtimeexception-gson-parsing-exception-failed-to-invoke-protected-java

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值