相关疑难解决方法(0)

执行ContentResolver插入时出错

执行插入新数据到内容提供程序时出错,请参见下面的代码,PS。我只是将下面的代码直接放入 Activity 的 onCreate() 中,然后执行。

ContentValues values=new ContentValues();
values.put(MediaStore.Audio.Media.TITLE,"Example Song");
values.put(MediaStore.Audio.Media.ARTIST,"Unknown");

getContentResolver().insert(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,values);
Run Code Online (Sandbox Code Playgroud)

只是简单地插入新的歌曲数据,但出现以下错误。

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.lastIndexOf(int)' on a null object reference
at android.os.Parcel.readException(Parcel.java:1605)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
at android.content.ContentProviderProxy.insert(ContentProviderNative.java:476)
at android.content.ContentResolver.insert(ContentResolver.java:1254)
at com.example.flover.contentproviderdemo.MainActivity.onCreate(MainActivity.java:48)
Run Code Online (Sandbox Code Playgroud)

谁能告诉我为什么?提前致谢。

android

3
推荐指数
1
解决办法
3340
查看次数

标签 统计

android ×1