類第三片段:片段(){
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?,
): View? {
val view2 = inflater.inflate(R.layout.fragment_third, container, false)
val a = arrayOf("Java","C","C ","Python","Kotlin")
var l1: ListView = view2.findViewById(R.id.list)
val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, a)
l1.adapter = adapter
return view2
這在“ArrayAdapter”上的 alt enter 上顯示
不能使用提供的引數呼叫以下函式。(Context, Int, Array<(out) TypeVariable(T)!>) where T = TypeVariable(T) for constructor ArrayAdapter<T : Any!>(context: Context, resource: Int, objects: Array<(out) T !>) 在 android.widget.ArrayAdapter (Context, Int, Int) 中定義,其中 T = TypeVariable(T) 用于在 android 中定義的建構式 ArrayAdapter<T: Any!>(context: Context, resource: Int, textViewResourceId: Int)。 widget.ArrayAdapter (Context, Int, (Mutable)List<TypeVariable(T)!>) where T = TypeVariable(T) for constructor ArrayAdapter<T : Any!>(context: Context, resource: Int, objects: (Mutable) List<T!>) 在 android.widget.ArrayAdapter 中定義
uj5u.com熱心網友回復:
該錯誤告訴您 ArrayAdapter 建構式的第一個引數需要是 Context,因此請替換this為回傳背景關系的內容,例如requireActivity().
val adapter = ArrayAdapter(requireActivity(), android.R.layout.simple_list_item_1, a)
在此范圍內this指的是片段,它不是 Context 物件。
您可以通過添加一些換行符來稍微分解該錯誤訊息以使其更易于閱讀。它告訴您存在三個有效的建構式,具有以下簽名,并且您提供的引數與其中任何一個都不匹配。
None of the following functions can be called with the arguments supplied.
(Context, Int, Array<(out) TypeVariable(T)!>) where T = TypeVariable(T)
for constructor ArrayAdapter<T : Any!>(context: Context, resource: Int, objects: Array<(out) T!>)
defined in android.widget.ArrayAdapter
(Context, Int, Int) where T = TypeVariable(T)
for constructor ArrayAdapter<T : Any!>(context: Context, resource: Int, textViewResourceId: Int)
defined in android.widget.ArrayAdapter
(Context, Int, (Mutable)List<TypeVariable(T)!>) where T = TypeVariable(T)
for constructor ArrayAdapter<T : Any!>(context: Context, resource: Int, objects: (Mutable)List<T!>)
defined in android.widget.ArrayAdapter
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/465182.html
上一篇:如何在BottomNavigationBarFlutter中獲得可擴展的TextFormField
下一篇:從具有二進制值的字典生成對
