Reputation: 137
When I download the image using the browser, I get the answer.
I use the same server to download the image using Android and Retrofit2, the image is well uplode and I see the result of processing in the terminal, but I get nothing in the application.
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()));
}
});
Here are the errors
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)
And
java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
The result class:
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;
}
}
Upvotes: 0
Views: 370
Reputation: 22
I have been through the same error, the main issue
the response which you are getting from the API is in an array format
But you are trying to get in object format.
Check your Response Model.
Upvotes: 1