注册改造

时间:2018-02-02 06:22:36

标签: android retrofit

 public void onResponse(Call<RegisterModel> call, Response<RegisterModel> response) {

                if(response.body().getSuccess()==1){

                startActivity(new Intent(getApplicationContext(), MainActivity.class));

                Toast.makeText(RegisterActivity.this, "Registration successfully ", Toast.LENGTH_SHORT).show();

                }
                    if(response.body().getSuccess()==0){

                        Toast.makeText(RegisterActivity.this, "Entered Email already exit ", Toast.LENGTH_SHORT).show();
                    }
                 }

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

                Toast.makeText(RegisterActivity.this, "Registration failed ", Toast.LENGTH_SHORT).show();
             }
         });

光标自动出现故障块...

1 个答案:

答案 0 :(得分:0)

请打印您的响应日志代码并使用if (response.isSuccessful())了解响应是否成功

Call<ResponseBean> registerCall = ApiHandler.getApiService().ApiName(ApiJsonMap());
        registerCall.enqueue(new retrofit2.Callback<ResponseBean>() {
            @Override
            public void onResponse(Call<ResponseBean> registerCall, retrofit2.Response<ResponseBean> response) {

                try {
                    //print respone
                    Log.e(" Full json gson => ", new Gson().toJson(response));
                    JSONObject jsonObj = new JSONObject(new Gson().toJson(response).toString());
                    Log.e(" responce => ", jsonObj.getJSONObject("body").toString());

                    if (response.isSuccessful()) {

                        dialog.dismiss();
                        int success = response.body().getSuccess();
                        if (success == 1) {



                        } else if (success == 0) {



                        }  
                    } else {
                        dialog.dismiss();


                    }


                } catch (Exception e) {
                    e.printStackTrace();
                    try {
                        Log.e("Tag", "error=" + e.toString());

                        dialog.dismiss();
                    } catch (Resources.NotFoundException e1) {
                        e1.printStackTrace();
                    }

                }
            }

            @Override
            public void onFailure(Call<ResponseBean> call, Throwable t) {
                try {
                    Log.e("Tag", "error" + t.toString());

                    dialog.dismiss();
                } catch (Resources.NotFoundException e) {
                    e.printStackTrace();
                }
            }

        });

更多help follow my answer分步实施