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的新手,我在构造函数中添加了一个参数,它会抛出这个错误吗?我不明白如何解决这个问题。任何帮助都是值得感激的 Error public constructor AppView(context: Context, _listener: OnFragmentInteractionListener, _position: Int)defined in com.views.home.AppView @JvmOverloads public constructor AppView(mlist

我是kotlin的新手,我在构造函数中添加了一个参数,它会抛出这个错误吗?我不明白如何解决这个问题。任何帮助都是值得感激的

Error public constructor AppView(context: Context, _listener: OnFragmentInteractionListener, _position: Int)defined in com.views.home.AppView @JvmOverloads public constructor AppView(mlist: StoreViewMap, context: Context, attrs: AttributeSet? = ..., defStyle: Int = ...) defined in com.views.home.AppView




class AppView @JvmOverloads constructor(mlist: StoreViewMap, context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) :
LinearLayout(context, attrs, defStyle) {
private lateinit var listener: OnFragmentInteractionListener
private var position = 0
private val mainView: View
var mlistener: StoreViewMap = mlist

constructor(context: Context, _listener: OnFragmentInteractionListener, _position: Int) : this(context) {
    listener = _listener
    position = _position

    initFeed()
}

init {
    val layoutInflater: LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
    mainView = layoutInflater.inflate(R.layout.view_home_feed, this)
}

private fun initFeed() {
    mainView.homeSwipeLayout.setOnRefreshListener { fetchSlots() }
    loadContentSlots(DataCaching(context).getContentSlots())
}

}

您必须在第一个构造函数中为
mList
添加默认值,或者在第二个构造函数中添加
StoreViewMap
参数

您必须在第一个构造函数中为
mList
添加默认值,或者在第二个构造函数中添加
StoreViewMap
参数

您正在调用自己的构造函数构造函数,这意味着如果定义构造函数参数,调用构造函数将忽略它们

constructor(context: Context) : this(context, null)

constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)

constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs)
这里第一个构造函数调用第二个,第二个调用第三个,但是第三个调用类中继承的类
LinearLayout
的构造函数

解决方案是创建一个forth构造函数,并向其中添加所需的参数,例如:

constructor(context: Context, mlist: StoreViewMap, _listener: OnFragmentInteractionListener, _position: Int) : this(context){
    // your code
}

此构造函数将调用第一个构造函数

您通过调用此(上下文)调用自己的构造函数,这意味着如果定义构造函数参数,调用构造函数将忽略它们

constructor(context: Context) : this(context, null)

constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)

constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs)
这里第一个构造函数调用第二个,第二个调用第三个,但是第三个调用类中继承的类
LinearLayout
的构造函数

解决方案是创建一个forth构造函数,并向其中添加所需的参数,例如:

constructor(context: Context, mlist: StoreViewMap, _listener: OnFragmentInteractionListener, _position: Int) : this(context){
    // your code
}

此构造函数将调用第一个构造函数

您的第一个构造函数有4个参数,2个带有默认值,在第二个构造函数中,您调用的是第一个构造函数->此(上下文),因此未提供参数mList,这会导致错误,您应该调用第一个构造函数->此(mList,上下文)或者在第一个构造函数中提供一个默认值,就像使用attrs和defstyle一样。第一个构造函数有4个参数,2个带有默认值,在第二个构造函数中调用第一个构造函数->this(上下文),因此没有提供参数mList,这会导致错误,您应该调用第一个构造函数->this(mList,context),或者在第一个构造函数中提供一个默认值,就像使用attrs和defStyle一样