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 改型2 API请求永远不会返回。为什么?_Android_Kotlin_Retrofit2 - Fatal编程技术网

Android 改型2 API请求永远不会返回。为什么?

Android 改型2 API请求永远不会返回。为什么?,android,kotlin,retrofit2,Android,Kotlin,Retrofit2,我有一个API服务: private const val BASE_URL = "https://www.random.org/integers/?num=1&min=1&max=6&col=1&base=10&format=plain&rnd=new" interface FooApiService { @GET suspend fun getInt(): Call<Int> } object FooApi {

我有一个API服务:

private const val BASE_URL = "https://www.random.org/integers/?num=1&min=1&max=6&col=1&base=10&format=plain&rnd=new"

interface FooApiService {
  @GET
  suspend fun getInt():
    Call<Int>
}

object FooApi {
    val retrofitService : FooApiService by lazy {
        retrofit.create(FooApiService::class.java)
    }
}

为什么?

不要认为你应该将
suspend
Call
一起使用,因为它们都在延迟 试着换成

接口服务{
@得到
suspend fun getInt():Int
}
检查它是否有效

编辑: 另外,您应该参考并检查如何使用
@Path
@Query

private const val BASE\u URL=”https://www.random.org/"
接口服务{
@获取(“整数/”)
暂停娱乐(
@查询(“num”)num:Int,
@查询(“min”)min:Int,
@查询(“max”)max:Int,
@查询(“列”)列:Int,
@查询(“基”)基:Int,
@查询(“格式”)格式:字符串,
@查询(“rnd”)rnd:String,
):Int
}

reformation.create(FooApiService::class.java)如何初始化改型?谢谢,这通常是正确的(我承认人为的基本URL是错误的;您不能有查询参数,否则会导致异常)。另外,async不会重新抛出异常,这就是为什么所有的东西都会保持沉默。删除呼叫修复了我的代码。
private var job = Job()
private val fooScope = CoroutineScope(job + Dispatchers.IO)

private fun doStuff() {
  fooScope.async {
    FooApi.retrofitService.getInt().execute()
    Log.i(TAG, "We never reach here! Why?")
  }
}