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 被ArrayAdapter卡住了_Android_Kotlin_Android Arrayadapter - Fatal编程技术网

Android 被ArrayAdapter卡住了

Android 被ArrayAdapter卡住了,android,kotlin,android-arrayadapter,Android,Kotlin,Android Arrayadapter,我正在把编写Kotlin代码作为一种爱好,但我遇到了麻烦。我得到以下错误: None of the following functions can be called with the arguments supplied: public constructor ArrayAdapter<T : Any!>(context: Context, resource: Int, objects: Array<(out) TypeVariable(T)!>) defined i

我正在把编写Kotlin代码作为一种爱好,但我遇到了麻烦。我得到以下错误:

None of the following functions can be called with the arguments supplied: 
public constructor ArrayAdapter<T : Any!>(context: Context, resource: Int, objects: Array<(out) TypeVariable(T)!>) defined in android.widget.ArrayAdapter
public constructor ArrayAdapter<T : Any!>(context: Context, resource: Int, textViewResourceId: Int) defined in android.widget.ArrayAdapter
public constructor ArrayAdapter<T : Any!>(context: Context, resource: Int, objects: (Mutable)List<TypeVariable(T)!>) defined in android.widget.ArrayAdapter
使用提供的参数无法调用以下函数:
在android.widget.ArrayAdapter中定义的公共构造函数ArrayAdapter(上下文:context,资源:Int,对象:数组)
在android.widget.ArrayAdapter中定义的公共构造函数ArrayAdapter(上下文:context,资源:Int,textViewResourceId:Int)
在android.widget.ArrayAdapter中定义的公共构造函数ArrayAdapter(上下文:context,资源:Int,对象:(可变)列表)
在我从openweather添加API以获取一些数据之前,它一直运行良好。 感谢您的帮助

这是我的密码:

package com.example.myweatherapp

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.ListView
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

class ForecastActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_forecast)



         var retriever = WeatherRetriever()

            val callback = object : Callback<Weather> {
                override fun onFailure(call: Call<Weather>?, t: Throwable) {
                println("It failed")
                }

                override fun onResponse(
                    call: Call<Weather>?, response: Response<Weather>?) {
                    println("It wORKED")

                    println(response?.body()?.main)

                    title = response?.body()?.name

                    var forecasts = response?.body()?.main

                    var castListView = findViewById<ListView>(R.id.forecastListView)

                    var adapter = ArrayAdapter(this@ForecastActivity,android.R.layout.simple_list_item_1,forecasts)

                    castListView.adapter=adapter
                }

            }
            retriever.getForecast(callback)
        }

        }
package com.example.myweatherapp
导入androidx.appcompat.app.appcompat活动
导入android.os.Bundle
导入android.widget.ArrayAdapter
导入android.widget.ListView
2.致电
导入2.回调
2.回应
类ForecasActivity:AppCompatActivity(){
重写创建时的乐趣(savedInstanceState:Bundle?){
super.onCreate(savedInstanceState)
setContentView(R.layout.activity\U forecast)
var retriever=WeatherRetriever()
val callback=object:callback{
覆盖失效时的乐趣(调用:调用?,t:可丢弃){
println(“它失败了”)
}
覆盖响应(
呼叫:呼叫?,响应:响应?){
println(“它起作用了”)
println(响应?.body()?.main)
title=响应?.body()?.name
var预测=响应?.body()?.main
var castListView=findViewById(R.id.forecastListView)
var适配器=阵列适配器(this@ForecastActivity,android.R.layout.simple_list_item_1,预测)
castListView.adapter=适配器
}
}
retriever.getForecast(回调)
}
}
ArrayAdapter需要数组/对象列表作为第三个参数,但
预测
只是响应主体

您需要解析响应并准备对象的列表/数组(即字符串标题)作为ArrayAdapter构造函数中的第三个参数传递

ArrayAdapter需要数组/对象列表作为第三个参数,但
预测
只是响应主体


您需要解析响应并准备一个对象列表/数组(即字符串标题),作为ArrayAdapter构造函数中的第三个参数传递。

响应.Body.Main的类型是什么?它需要是一个数组或列表。另外,如果响应或正文为null,您将遇到问题。我正在尝试访问此JSON文件上的“Main”数组,并将其内容作为结果:[link]响应.body.Main的类型是什么?它需要是一个数组或列表。另外,如果响应或正文为null,则会出现问题。我正在尝试获取此JSON文件上的“Main”数组,并将其内容作为结果:[link]
ArrayAdapter(this@ForecastActivity,android.R.layout.simple_list_item_1,forecasts)