gson 字符串转换android对象报错 Can't instantiate abstract class java.lang.ClassLoader
来源:互联网 发布:阿里云 cn域名隐私 编辑:程序博客网 时间:2024/06/01 21:18
在使用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
- gson 字符串转换android对象报错 Can't instantiate abstract class java.lang.ClassLoader
- java.lang.InstantiationException: can't instantiate class
- Caused by: java.lang.InstantiationException: can't instantiate class报错记录
- 使用Gson将对象转换成字符串的时候报java.lang.StackOverflowError
- java.lang.Classloader、java.lang.Class对象
- 报错Caused by: java.lang.ClassNotFoundException: Didn't find class "android.view.PagerTabStrip"
- 开发问题及解决 E/AndroidRuntime(15377): Caused by: java.lang.InstantiationException: can't instantiate clas
- android studio报:java.lang.IllegalStateException: Can't change tag of fragment
- Unable to instantiate activity ComponentInfo java.lang.ClassNotFoundException: Didn't find class on
- Unable to instantiate activity ComponentInfo{}: java.lang.ClassNotFoundException: Didn't find class
- Gson转换JSON字符串和Java对象
- 报错java.lang.NoClassDefFoundError: com.google.gson.Gson
- Android FTP ftpClient.listFiles()报java.lang.ClassNotFoundException: Didn't find class "Windows_NT"
- Android studio报:Caused by: java.lang.ClassNotFoundException: Didn't find class "xhs.com.view.ParentV
- Android studio报:Caused by: java.lang.ClassNotFoundException: Didn't find class "xhs.com.view.ParentV
- Tomcat启动报错:java.lang.IllegalArgumentException: Can't convert argument:null
- Android程序 依赖库引用Gson 报java.lang.NoClassDefFoundError: com/google/gson/Gson 解决方法
- Android程序 依赖库引用Gson 报java.lang.NoClassDefFoundError: com/google/gson/Gson 解决
- fping多线程
- 1041. Be Unique (20)
- GoldenGate中使用FILTER,COMPUTE 和SQLEXEC命令
- db.properties 在SSM 框架中的使用
- LeetCode 541. Reverse String II
- gson 字符串转换android对象报错 Can't instantiate abstract class java.lang.ClassLoader
- I/O概述及其分类
- Xcode8 插件安装。
- 1896: 树的判定(并查集)
- 如何让{dede:channel}有子栏目显示子栏目,无子栏目不显示同级栏目
- ARM裸机开发之基于S3C2451的电子相册开发
- python 中filter()函数
- 如何查看进程的信息(线程数)
- 自定义一个布局实现标签流