当我使用浏览器下载图像时,我得到答案。
我使用相同的服务器使用Android和Retrofit2下载图像,图像完全上传,我在终端中看到了处理结果,但我在应用程序中什么也没得到。
resultCall.enqueue(new Callback<Result>() {
@Override
public void onResponse(Call<Result> call, Response<Result> response) {
// Response Success or Fail
if (response.isSuccessful()) {
if (response.body().getResult().equals("success")) {
Snackbar.make(parentView, R.string.string_upload_success, Snackbar.LENGTH_LONG).show();
Log.i("onResponse", "File Uploaded Successfully");
} else {
Snackbar.make(parentView, R.string.string_upload_fail, Snackbar.LENGTH_LONG).show();
Log.i("onResponse", " Something went wrong");
}
} else {
Snackbar.make(parentView, R.string.string_upload_fail, Snackbar.LENGTH_LONG).show();
Log.i("onResponse", " Something went wrong");
}
}
@Override
public void onFailure(Call<Result> call, Throwable t) {
Log.i("onFailure", t.getMessage());
Log.e("onFailure", Arrays.toString(t.getStackTrace()));
}
});
以下是错误
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220),
retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:37),
retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyC onverter.java:25), retrofit2.ServiceMethod.toResponse(ServiceMethod.java:116),
retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211),
retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:106),
okhttp3.RealCall$AsyncCall.execute(RealCall.java:133),
okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32),
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113),
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588),
java.lang.Thread.run(Thread.java:818)
并且
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
结果类:
public class Result {
@SerializedName("result")
@Expose
private String result;
/**
* @return The result
*/
public String getResult() {
return result;
}
/**
* @param result The result
*/
public void setResult(String result) {
this.result = result;
}
}
答案 0 :(得分:1)
我遇到了同样的错误,主要问题
您从API获得的响应是数组格式
但你正试图进入对象格式。
检查您的响应模型。