如何解决使用Gson将VideoView对象解析为json
我想将VideoView对象解析为json,以便可以使用jobparameters将其传递给Main Activity类以外的其他线程。
我的代码如下:
VideoView videoViewN = findViewById(R.id.video);
Gson g = new Gson();
String json = g.toJson(videoViewN); //this is the line that causes the error
PersistableBundle bundle = new PersistableBundle();
bundle.putString("VideoView",json);
JobInfo info = new JobInfo.Builder(123,componentName)
.setPersisted(true)
.setExtras(bundle)
.setPeriodic(5 * 60 * 1000)
.build();
但是它会引发如下错误:
2020-09-08 16:49:30.408 19352-19352/com.example.ses_adplatform_test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ses_adplatform_test,PID: 19352
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ses_adplatform_test/com.example.ses_adplatform_test.MainActivity}: java.lang.IllegalArgumentException: class android.widget.MediaController declares multiple JSON fields named mContext
我该如何解决?谢谢!
PS:之所以需要将其解析为json是因为jobparameters不接受字符串,int等以外的数据类型。我使用以下链接中的代码作为此解决方案的参考。 Android JobScheduling - I need to pass an object to my job but how?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。