我正在尝试从Kotlin文件查询内容提供者。请参见下面的代码:
var URI = Uri.parse("content://myprovider") var nameUri = Uri.withAppendedPath(URI, "name") cursor = contentResolver.query(nameUri, null, null, null, null)
When I run this code, I am getting below error
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter projection at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:165) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135) at android.content.ContentProviderProxy.query(ContentProviderNative.java:418) at android.content.ContentResolver.query(ContentResolver.java:802)
Now, when I checked the query method signature in ContentResolver class, this is what it is
public final @Nullable Cursor query(@RequiresPermission.Read @NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder)
As you can see, everything apart from Uri can be Nullable, so technically it should not throw this error.
Also, I tried giving projection but then it threw an error for selectionArgs.
Please help. Thanks in advance.
Note: Neither contentResolver not nameUri is null
你可以试试这个吗
override fun query(uri: Uri, projection: Array?, selection: String?, selectionArgs: Array ?, sortOrder: String?): Cursor? { //ur code return cursor }
参考此链接