if (checkPlayServices()) {
HashMap<String, RequestBody> map = new HashMap<>();
map.put(Constant.TYPE, ApiClient.makeTextRequestBody(String.valueOf(Constant.TYPE_STORE)));
map.put(Constant.DEVICE_TYPE, ApiClient.makeTextRequestBody(Constant.ANDROID));
Call<AppSetting> call = ApiClient.getClient().create(ApiInterface.class).getAppSettingDetail(map);
call.enqueue(new Callback<AppSetting>() {
@Override
public void onResponse(Call<AppSetting> call, Response<AppSetting> response) {//AppSetting.java response api
Toast.makeText(MainActivity.this, String.valueOf(response.body()), Toast.LENGTH_LONG).show();
if (response.isSuccessful()) {
// Toast.makeText(MainActivity.this, " onResponse: "+"response.successfully", Toast.LENGTH_LONG).show();
Utilities.printLog("MainActivity", "check app key --" + new Gson().toJson(response.body()));
if (response.body().isSuccess()) {
// Toast.makeText(MainActivity.this, " onResponse: "+"response is successfully", Toast.LENGTH_LONG).show();
if (parseContent.parseAppSettingDetails(response)) {
if (PreferenceHelper.getPreferenceHelper(MainActivity.this).isForceUpdate() && checkVersionCode(response.body().getVersionCode())) {
openUpdateAppDialog(response.body().isIsForceUpdate());
} else {
/** option if user still login go to home else go to RegisterLoginActivity.java **/
goToActivity();
}
}
} else {
Toast.makeText(MainActivity.this, response.message(), Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(MainActivity.this, response.message(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<AppSetting> call, Throwable t) {
// Toast.makeText(MainActivity.this, t.getMessage(), Toast.LENGTH_LONG).show();
Toast.makeText(MainActivity.this, t.getLocalizedMessage(), Toast.LENGTH_LONG).show();
Log.d("Retrofit", "Retrofit: onResponse not called, onFailure called instead... ");
Log.d("Retrofit", t.getStackTrace().toString());
Log.d("Retrofit", t.getMessage());
}
});
}
Asked
Active
Viewed 111 times
0

Jakir Hossain
- 3,830
- 1
- 15
- 29

faszz tech
- 11
- 1
- 1
- 2
-
1explain your question in detail. see https://stackoverflow.com/help/how-to-ask – Jakir Hossain Nov 05 '19 at 09:02
-
The Problem is when build apk with debug everything is ok, all jason display properly. But when build apk for release the retrofit goes to onFailure, with null json data. can any body help me on this – faszz tech Nov 06 '19 at 03:20
-
The Throwable.getMessage() ="Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $" – faszz tech Nov 06 '19 at 03:23
1 Answers
0
You could add setLenient
to your GsonBuilder()
like the following.
Gson gson = new GsonBuilder()
.setLenient()
.create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
Note: Make sure you have gson
dependency in your gradle
.
implementation 'com.google.code.gson:gson:2.8.6'

Jakir Hossain
- 3,830
- 1
- 15
- 29
-
when do that throwable = "java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $" why?? – faszz tech Nov 06 '19 at 06:18
-
for that exception see [this answer](https://stackoverflow.com/a/28418787/4854891) – Jakir Hossain Nov 06 '19 at 06:23
-
when create Gson its goes to com.google.gson not com.google.code.gson – faszz tech Nov 06 '19 at 06:40
-
but still throwable = "java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $" – faszz tech Nov 06 '19 at 07:25
-
You are getting the wrong response from your `API`. You are getting a `string` in response but it should be `object`. It can be happened due to many reasons. Better check your `API` in `Postman` and be sure that your `API` works fine and gives you a `JSON` in response. – Jakir Hossain Nov 06 '19 at 07:30
-
for your info the json return when using postman like: { "success": true, "message": 321, "is_use_referral": true, "is_verify_email": false, "is_verify_phone": false, "is_document_mandatory": true, "is_login_by_email": true, "is_login_by_phone": true, "is_login_by_social": true, "is_hide_optional_field": true, "is_profile_picture_required": true " } – faszz tech Nov 06 '19 at 08:49
-
To see your `request info` and `response code`, please add `Log.e("YOUR_TAG", "Request info: "+ call.request())` and `Log.e("YOUR_TAG", "Response code: "+ response.code())` inside `onResponse` and add `Log.e("YOUR_TAG", "Request info: "+ call.request())` inside `onFailure`. and let me know. – Jakir Hossain Nov 06 '19 at 09:05