在我工作的应用程序中,我有一个名为 addVideo 的方法,该方法在 AsyncTask 的 doInBackground 方法中被调用,它基本上只是将视频添加到媒体存储并返回其 uri:
public Uri addVideo(File videoFile) {
ContentValues values = new ContentValues(3);
values.put(MediaStore.Video.Media.TITLE, "My Video!");
values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
values.put(MediaStore.Video.Media.DATA, videoFile.getAbsolutePath());
return getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values);
}
我目前在线上遇到错误:
values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
这是日志猫:
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
at java.lang.Thread.run(Thread.java:1019)
Caused by: java.lang.NullPointerException
at com.myProject.add_video_project.AddToMediaStore.addVideo(Submit.java:121)
at com.myProject.add_video_project.AddToMediaStore$StartUploadChain.doInBackground(Submit.java:195)
at com.myProject.add_video_project.AddToMediaStore$StartUploadChain.doInBackground(Submit.java:167)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
关于可能发生什么的任何想法?谢谢!