无法在onResponse返回中获取任何数据,结果跳至onFailure。
它适用于我的其他应用程序,数据返回并成功显示,但同样的事情在此应用程序上失败了。
我尝试了其他代码,但仍然找不到问题,没有显示任何错误消息,有什么想法吗?
private void parseJSON() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Api.URL_DATA)
.addConverterFactory(GsonConverterFactory.create())
.build();
Api api = retrofit.create(Api.class);
Call<List<ListItem>> call = api.getList();
call.enqueue(new Callback<List<ListItem>>() {
@Override
public void onResponse(Call<List<ListItem>> call, retrofit2.Response<List<ListItem>> response) {
if (response.isSuccessful()) {
Toast.makeText(getApplicationContext(), "Server returned data", Toast.LENGTH_SHORT).show();
DeveloperList = response.body();
listAdapter.setList(DeveloperList);
progressDialog.hide();
}
else {
Toast.makeText(getApplicationContext(), "Server returned an error", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<List<ListItem>> call, Throwable t) {
progressDialog.hide();
Toast.makeText(getApplicationContext(), "This is an actual network failure...", Toast.LENGTH_SHORT).show();
}
});
}
最佳答案
您正在尝试将无法转换为数字(整数/ double )的字符串转换。在进行转换之前删除 $ 字符。
关于java - 改造Android GET失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56592453/