当emulater用户resgister成功运行应用程序但在设备应用app上运行时给出内部服务器错误如何解决

时间:2017-11-02 08:47:23

标签: java android node.js mongodb retrofit2

在模拟器用户注册成功时运行应用程序但在设备应用程序app上运行给出内部服务器错误如何解决..

这是register fragment.java代码

public class RegisterFragment extends Fragment {

public static final String TAG = RegisterFragment.class.getSimpleName();

private EditText mEtName;
private EditText mEtEmail;
private EditText mEtPassword;
private Button   mBtRegister;
private TextView mTvLogin;
private TextInputLayout mTiName;
private TextInputLayout mTiEmail;
private TextInputLayout mTiPassword;
private ProgressBar mProgressbar;

private CompositeSubscription mSubscriptions;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_register,container,false);
    mSubscriptions = new CompositeSubscription();
    initViews(view);
    return view;
}

private void initViews(View v) {

    mEtName = (EditText) v.findViewById(R.id.et_name);
    mEtEmail = (EditText) v.findViewById(R.id.et_email);
    mEtPassword = (EditText) v.findViewById(R.id.et_password);
    mBtRegister = (Button) v.findViewById(R.id.btn_register);
    mTvLogin = (TextView) v.findViewById(R.id.tv_login);
    mTiName = (TextInputLayout) v.findViewById(R.id.ti_name);
    mTiEmail = (TextInputLayout) v.findViewById(R.id.ti_email);
    mTiPassword = (TextInputLayout) v.findViewById(R.id.ti_password);
    mProgressbar = (ProgressBar) v.findViewById(R.id.progress);

    mBtRegister.setOnClickListener(view -> register());
    mTvLogin.setOnClickListener(view -> goToLogin());
}

private void register() {

    setError();

    String name = mEtName.getText().toString();
    String email = mEtEmail.getText().toString();
    String password = mEtPassword.getText().toString();

    int err = 0;

    if (!validateFields(name)) {

        err++;
        mTiName.setError("Name should not be empty !");
    }

    if (!validateEmail(email)) {

        err++;
        mTiEmail.setError("Email should be valid !");
    }

    if (!validateFields(password)) {

        err++;
        mTiPassword.setError("Password should not be empty !");
    }

    if (err == 0) {

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

        mProgressbar.setVisibility(View.VISIBLE);
        registerProcess(user);

    } else {

        showSnackBarMessage("Enter Valid Details !");
    }
}

private void setError() {

    mTiName.setError(null);
    mTiEmail.setError(null);
    mTiPassword.setError(null);
}

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(Response 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();
            Response response = gson.fromJson(errorBody,Response.class);
            showSnackBarMessage(response.getMessage());

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

        showSnackBarMessage("Network Error !");
    }
}

private void showSnackBarMessage(String message) {

    if (getView() != null) {

        Snackbar.make(getView(),message,Snackbar.LENGTH_SHORT).show();
    }
}

private void goToLogin(){

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    LoginFragment fragment = new LoginFragment();
    ft.replace(R.id.fragmentFrame, fragment, LoginFragment.TAG);
    ft.commit();
}

@Override
public void onDestroy() {
    super.onDestroy();
    mSubscriptions.unsubscribe();
}
}

this is gradle.build(app level) dependencies for my app

usb device connected that given error

this is logcat file

backend structure flow of data

0 个答案:

没有答案