【发布时间】:2018-05-25 14:31:20
【问题描述】:
我正在使用改造 2 对我的服务器进行 api 调用,但在尝试进行 api 调用时它被卡住了。这是我的代码
public interface GOTApi {
@GET("characters.json")
Call<GOTCharacterResponse> getCharacters();
}
获取数据的中间类
public class GOTCharacterResponse {
List<GOTCharacter> characters;
}
我的班级进行 api 调用
public class GOTService {
public static final String BASE_URL = "https://project-8424324399725905479.firebaseio.com/";
public static GOTApi getGOTApi(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
return retrofit.create(GOTApi.class);
}
public static void getCharacters(){
getGOTApi().getCharacters().enqueue(new Callback<GOTCharacterResponse>() {
@Override
public void onResponse(Call<GOTCharacterResponse> call, Response<GOTCharacterResponse> response) {
if(response.isSuccessful()){
}
}
@Override
public void onFailure(Call<GOTCharacterResponse> call, Throwable t) {
int a = 0;
}
});
}
}
这些是我正在使用的库
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'com.squareup.okhttp3:okhttp:3.3.1'
它总是卡在 getCharacters() 方法中。当然,我在 Mainfest 中设置了 Internet 权限。
【问题讨论】:
-
“卡住”是什么意思?碰撞?还是?
-
不,它没有崩溃,只是进程没有继续,我在logcat中看不到任何警告或错误
-
@aloj 你的问题解决了吗?我面临着类似的问题
标签: android retrofit retrofit2