1

my app returns this error message when I try to register a user. I know that there are many questions already that are similar to this but non of the answers there helped solve my problem. I'm new to android programming. your help is highly appreciated.

java.lang.IllegalStateException:Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $

below is my registerProcess

private void registerProcess(String name,String email,String password) {

    String tag_string_req = "req_register";
    //pDialog = new AlertDialog.Builder(getActivity());
    pDialog.setMessage("please wait");
    pDialog.show();

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


    Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Constants.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .build();

        RequestInterface requestInterface = retrofit.create(RequestInterface.class);
        User user = new User();
        user.setName(name);
        user.setEmail(email);
        user.setPassword(password);
        ServerRequest request = new ServerRequest();
        request.setOperation(Constants.REGISTER_OPERATION);
        request.setUser(user);
        Call<ServerResponse> response = requestInterface.operation(request);

        response.enqueue(new Callback<ServerResponse>() {
            private View view;
/*
        public View getView() {
            return view;

        }
        */

            @Override
            public void onResponse(Call<ServerResponse> call, retrofit2.Response<ServerResponse> response) {

                ServerResponse resp = response.body();

                //if(resp !=null)
                Toast.makeText(getApplicationContext(), resp.getMessage(), Toast.LENGTH_LONG).show();
                pDialog.dismiss();
            }


            @Override
            public void onFailure(Call<ServerResponse> call, Throwable t) {

                // progress.setVisibility(View.INVISIBLE);
                Log.d(Constants.TAG, "failed");
                Toast.makeText(getApplicationContext(), t.getLocalizedMessage(), Toast.LENGTH_LONG).show();
                pDialog.dismiss();


            }
        });
    }
Mani
  • 291
  • 1
  • 2
  • 10

0 Answers0