0

Expected BEGIN_OBJECT but was STRING at line 1 column 1 it Ocuure Illigal statement exception and JsonSyntaxException

This is content from my RegisterFragment:

User user = new User();
        user.setName(name);
        user.setEmail(email);
        user.setPassword(password);
registerProcess(user);

 private void registerProcess(User user) {

    mSubscriptions.add(NetworkUtil.getRetrofit().register(user)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .subscribe(this::handleResponse, this::handleError));
}
private void handleResponse(MyResponse response) {

    mProgressbar.setVisibility(View.GONE);
    showSnackBarMessage(response.getMessage());
}

private void handleError(Throwable error) {

    mProgressbar.setVisibility(View.GONE);

    if (error instanceof HttpException) {

        Gson gson = new GsonBuilder().create();

        try {

            String errorBody = ((HttpException) error).response().errorBody().string();
            MyResponse response = gson.fromJson(errorBody, MyResponse.class);
           Log.i(TAG, "handleError: "+ response.getMessage());
            showSnackBarMessage(response.getMessage());

        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {

        showSnackBarMessage("Network Error !");
    }
}
Ashik Azeez
  • 404
  • 5
  • 8
  • 1
    please add your json response here. – Ratilal Chopda Jan 29 '18 at 05:42
  • Share you JSON and Parsing code – Ramesh sambu Jan 29 '18 at 05:47
  • private void handleError(Throwable error) { mProgressbar.setVisibility(View.GONE); if (error instanceof HttpException) { Gson gson = new GsonBuilder().create(); String errorBody = ((HttpException) error).response().errorBody().string(); MyResponse response = gson.fromJson(errorBody, MyResponse.class); } – Ashik Azeez Jan 29 '18 at 05:58
  • We don't (only) need the code how you received your Jason but the content of the received Jason itself. And please don't add information as comment but rather edit your question and add additional information there. – derHugo Jan 29 '18 at 06:03

0 Answers0