小编Kes*_*sco的帖子

将kotlin与ContentResolver一起使用会导致IllegalArgumentException

我试着用Kotlin写一个应用程序.我把contentprovider查询sql放在另一个进程上.在主进程中通过ContentResolver查询时,应用程序崩溃了.

代码是:

protected fun select(uri: Uri, sql: String, vararg args: Any): Cursor {
    val sArgs = Array(args.size(), { i -> lang.String.valueOf(args.get(i)) })
    return context.getContentResolver().query(uri, null, sql, sArgs, null)
}

public fun selectAllAccounts(): Array<Account> {
    val cursor = select(parseUri(AccountSchema.TABLE_NAME), "select * from " + AccountSchema.TABLE_NAME)
    val accounts = Array(cursor.getCount(), { i ->
        if (!cursor.moveToPosition(i)) {
            throw RuntimeException("Cursor move failed")
        }
        Account(context, cursor)
    })
    return accounts
}
Run Code Online (Sandbox Code Playgroud)

它将抛出IllegalArgumentException:

05-20 10:27:21.120    3337-3337/com.kescoode.yomail E/AndroidRuntime? FATAL EXCEPTION: main
Process: com.kescoode.yomail, PID: 3337
java.lang.RuntimeException: Unable to …
Run Code Online (Sandbox Code Playgroud)

android kotlin

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

标签 统计

android ×1

kotlin ×1