Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/217.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Kotlin继承-没有为参数上下文传递值_Android_Kotlin - Fatal编程技术网

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

Android Kotlin继承-没有为参数上下文传递值,android,kotlin,Android,Kotlin,我正在尝试使用kotlin for android构建一个AccountAuthenticator类。但是当尝试实现AbstractAccountAuthenticator类时,我在编译时遇到以下异常: 没有为参数上下文传递值 我不完全确定这意味着什么,也找不到任何解决方法 以下是相关代码: import android.accounts.AbstractAccountAuthenticator import android.accounts.Account import android.acc

我正在尝试使用kotlin for android构建一个
AccountAuthenticator
类。但是当尝试实现
AbstractAccountAuthenticator
类时,我在编译时遇到以下异常:

没有为参数上下文传递值

我不完全确定这意味着什么,也找不到任何解决方法

以下是相关代码:

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

class AccountAuthenticator: AbstractAccountAuthenticator() {}

有人知道这意味着什么、为什么以及如何修复它吗?

AbstractAccountAuthenticator
接受一个
上下文
参数。因此,您必须以某种方式将
上下文
传递给它,例如,您的
AccountAuthenticator
也可以有一个
上下文
参数:

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

我对Kotlin了解不多,但是
AbstractAccountAuthenticator
构造函数采用
上下文
请参见


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

解决了这个问题,谢谢。在该上下文中值得添加的内容是从
android.content.context
导入的。我只缺少细节。简单地说,我将“context”参数从继承的类传递到基类超级方法。