我正在使用翻新和rxkotlin调用api。但是,当我启动片段时,应用程序崩溃而没有任何通知,或者在Studio Logcat中未显示任何错误消息。这是代码。 从这里我被称为apis接口
try {
if (disposable == null) {
Log.e("disposable","reached")
disposable = api.getUsers(api_key,
"json",
"1",
"flickr.interestingness.getList")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe (
{
data: FlickrPhoto? -> Log.e("flickr photo",data!!.photo?.get(0)?.secret)
}
)
Log.e("disposable1","reached")
}
}
catch (e: Exception){
Log.e("flickr fragment",e.toString())
}
这是api接口代码:
interface API {
@GET("services/rest")
fun getUsers(@Query("format") format : String,
@Query("api_key") api_key : String,
@Query("nojsoncallback") nojsoncallback : String,
@Query("method") method : String
) : Observable<FlickrPhoto>
companion object{
fun createView():API{
Log.e("apis","creatview")
try {
val retrofit = Retrofit.Builder()
.baseUrl("https://api.flickr.com/")
.addCallAdapterFactory(
RxJava2CallAdapterFactory.create())
.addConverterFactory(
GsonConverterFactory.create())
.build()
Log.e("retrofit",retrofit.toString())
return retrofit.create(API::class.java)
}
catch (e: Exception){
Log.e("api exception",e.message)
}
Log.e("apis","creatview retrofit null")
return null!!
}
}
}
这是logcat:
11-07 03:47:07.527 11627-11627/com.redvelvet.abhi.imagesmapling E/disposable: reached
11-07 03:47:07.529 11627-11627/com.redvelvet.abhi.imagesmapling E/apis: creatview
11-07 03:47:07.620 11627-11627/com.redvelvet.abhi.imagesmapling E/retrofit: retrofit2.Retrofit@ec11d24
11-07 03:47:07.751 11627-11627/com.redvelvet.abhi.imagesmapling E/disposable1: reached