Kotlin 继承 - 没有为参数上下文传递值

问题描述 投票:0回答:3

我正在尝试使用适用于 Android 的 kotlin 构建一个

AccountAuthenticator
类。但是当尝试实现
AbstractAccountAuthenticator
类时,我在编译时遇到以下异常:

No value passed for parameter context

我不完全确定这意味着什么,也找不到任何有关如何解决它的信息。

相关代码如下:

import android.accounts.AbstractAccountAuthenticator
import android.accounts.Account
import android.accounts.AccountAuthenticatorResponse
import android.os.Bundle

class AccountAuthenticator: AbstractAccountAuthenticator() {}

有谁知道这意味着什么、为什么以及如何解决它?

android kotlin
3个回答
13
投票

AbstractAccountAuthenticator
constructor 采用
Context context
参数。所以你必须以某种方式传递一个
Context
给它,例如,你的
AccountAuthenticator
也可以有一个
Context
参数:

class AccountAuthenticator(context: Context): AbstractAccountAuthenticator(context) {}

1
投票

我对 Kotlin 不太了解,但是

AbstractAccountAuthenticator
构造函数需要
Context
请参阅 here

所以我猜你必须实现这个构造函数和其他相关的抽象方法。


0
投票

Tengo 2 pantallas separadas pero identicas,在第二个屏幕上显示我销售错误,没有为参数“text”传递值 algun consejo?

© www.soinside.com 2019 - 2024. All rights reserved.