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

我试图建立一个AccountAuthenticator类与Android的kotlin。 但是当试图实现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() {} 

有谁知道这是什么意思,为什么,以及如何解决它?

AbstractAccountAuthenticator的构造函数需要一个Context context参数。 所以你必须以某种方式传递一个Context ,例如,你的AccountAuthenticator也可以有一个Context参数:

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

我不太了解Kotlin,但AbstractAccountAuthenticator构造函数需要一个Context 在这里看到。

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