android - 使用 Gson 将 VideoView 对象解析为 json
问题描述
我想将 VideoView 对象解析为 json,以便可以使用作业参数将其传递给 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 - 我需要将一个对象传递给我的工作,但如何?
解决方案
推荐阅读
- javascript - 将 Chartjs 图像从 Angular 应用程序拖放到 powerpoint
- azure - 与 API 通信以获取数据的 react/angular 应用程序可以被视为静态 Web 应用程序
- chart.js - Chart.js 3.5.1 关于zeroLineColor的属性问题
- python - 在不使用预定义库的情况下生成集合的幂集?
- google-apps-script - 使用 File.moveTo 时出现错误(?)错误
- c - 如何通过 mpi send 在另一个结构内发送一个结构
- excel - 向每个团队成员发送电子邮件,同时跳过那些没有现有工作表的成员
- reactjs - 当我的本地存储不为空时,如何直接呈现我的菜单?
- python - 在“with”语句中提取代码并将其从运行时中删除
- macos - 构建 install4j 时如何将参数传递给 Java FX 应用程序?