0

問題が発生しました。私の非同期タスクはうまくやっています。しかし、私のOnPostExecuteで、私はこれを手に入れました:

if (error = true) {
   loginErrorMsg.setText("Incorrect username/password");
} else {
   loginErrorMsg.setText("");
}

彼がまだ表示している場合error == falseでも:ユーザー名/パスワードが正しくありません...

class LoginUser extends AsyncTask<String, String, String> {

    /**
     * Before starting background thread Show Progress Dialog
     * */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(LoginActivity.this);
        pDialog.setMessage("Loading");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
        email = inputEmail.getText().toString();
        password = inputPassword.getText().toString();

    }

    /**
     * Creating product
     * */
    protected String doInBackground(String... args) {

        UserFunctions userFunction = new UserFunctions();
        Log.d("Button", "Login");
        JSONObject json = userFunction.loginUser(email, password);
     // check for login response
        try {
            if (json.getString(KEY_SUCCESS) != null) {
                String res = json.getString(KEY_SUCCESS); 
                if(Integer.parseInt(res) == 1){
                    // user successfully logged in
                    // Store user details in SQLite Database
                    DatabaseHandler db = new DatabaseHandler(getApplicationContext());
                    JSONObject json_user = json.getJSONObject("user");

                    // Clear all previous data in database
                    userFunction.logoutUser(getApplicationContext());
                    db.addUser(json_user.getString(KEY_NAME), json_user.getString(KEY_EMAIL), json.getString(KEY_UID), json_user.getString(KEY_CREATED_AT));                        

                    // Launch Dashboard Screen
                    Intent dashboard = new Intent(getApplicationContext(), Main.class);

                    // Close all views before launching Dashboard
                    dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(dashboard);

                    // Close Login Screen
                    finish();
                }else{
                    // Error in login
                    error = true;
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }


        return null;
    }

    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog once done
        pDialog.dismiss();


        if( error = true){
            loginErrorMsg.setText("Incorrect username/password");
        } else {
            loginErrorMsg.setText("");
        }
    }

}
4

4 に答える 4

3

二重等号を使用する必要があります。

if (error == true) {   
于 2012-12-03T12:48:01.633 に答える
2

Java で等価性テストに使用される演算子は===代入演算子です。今、あなたのerror意志は常にあなたがそれtrueに割り当てる原因ですtrue。お役に立てれば。

于 2012-12-03T12:49:07.600 に答える
1

比較するには、 error == truenotを使用する必要error = trueがあります。これは割り当てであり、常に true です。

于 2012-12-03T12:48:24.990 に答える
1

に変更if(error = true)if(error == true)ます。

于 2012-12-03T12:48:26.687 に答える