使用电子邮件和密码NPE的Firebase身份验证

时间:2016-04-15 21:03:59

标签: android firebase firebase-authentication

在尝试使用Firebase进行电子邮件和密码身份验证登录时,10%的情况下存在空指针异常。这只发生在apk版本中。它不会出现在调试应用程序中。它说它不能为电子邮件传递null。但电子邮件已填写。否则Firebase会出现错误代码,但不是npe。 这是错误消息:

  /**
   * Uses the route to handle incoming connections and requests for the ServerBinding.
   */
  def handleConnectionsWithRoute(interface: String, port: Int, route: Route, system: ActorSystem, materializer: Materializer): CompletionStage[ServerBinding] = {
    implicit val s = system
    implicit val m = materializer

    import system.dispatcher
    val r: server.Route = RouteImplementation(route)
    Http(system).bind(interface, port).toMat(Sink.foreach(_.handleWith(akka.http.scaladsl.server.RouteResult.route2HandlerFlow(r))))(Keep.left).run()(materializer).toJava
  }

道歉。我应该直接添加我的代码。 首先验证输入:

Caused by: java.lang.NullPointerException: Can't pass null for argument 'email' in authWithPassword()

at com.firebase.client.Firebase.authWithPassword(Unknown Source)

at com.example.verdienapp.ui.start.StartActivity$LoginTask.doInBackground(Unknown Source)

at com.example.verdienapp.ui.start.StartActivity$LoginTask.doInBackground(Unknown Source)

然后是登录事件:

private void validate() {
    this.mEmailEditText.setError(null);
    this.mPasswordEditText.setError(null);
    String email = this.mEmailEditText.getText().toString();
    String password = this.mPasswordEditText.getText().toString();
    boolean cancel = false;
    View focusView = null;
    if (TextUtils.isEmpty(password)) {
        this.mPasswordEditText.setError(getString(R.string.error_field_required));
        focusView = this.mPasswordEditText;
        cancel = true;
    } else if (password.length() < 6) {
        this.mPasswordEditText.setError(getString(R.string.error_invalid_password));
        focusView = this.mPasswordEditText;
        cancel = true;
    }
    if (TextUtils.isEmpty(email)) {
        this.mEmailEditText.setError(getString(R.string.error_field_required));
        focusView = this.mEmailEditText;
        cancel = true;
    } else if (!email.contains("@")) {
        this.mEmailEditText.setError(getString(R.string.error_invalid_email));
        focusView = this.mEmailEditText;
        cancel = true;
    }
    if (cancel) {
        if (focusView != null) {
            focusView.requestFocus();
        }
    } else {
        Utils.closeKeyboard(getActivity(), this.mEmailEditText);
        LoginEvent event = new LoginEvent(R.id.button_login, email, password);
        BusProvider.getInstance().post(event);


    }
}

最后在AsyncTask中使用Firebase登录过程。

private void login(final ButtonEvent buttonEvent) {
    LoginEvent loginEvent = (LoginEvent) buttonEvent;
    new LoginTask().execute();
    email = loginEvent.getEmail();
    password = loginEvent.getPassword();

}

0 个答案:

没有答案