1

PHPサーバーに接続し、サーバーに保存されているデータベースからユーザー名パスワードを照合することにより、Androidアプリのログインアクティビティを作成しようとしています。ユーザーがドナーの場合はステートメント 1 を取得し、ユーザーが病院の場合は 0 を取得します。ただし、次のコードでは、結果が o であっても if ステートメントは常に else 部分の後に続きます。

ここに私のログインクラスがあります

          login_hos.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            String   mUsername = username.getText().toString();
            String  mPassword = password.getText().toString();

            tryLogin(mUsername, mPassword);
            try {
                if (!response.equals("Login Error !")&&(!response.equals("Connection Error !"))){
                    String arr[]=response.split(",");
                    String type=arr[1];
                    type.trim();
          // String usr="donor";


        if (type.equals("0")) {
                            Log.v("type", type);
                            Intent intent = new Intent(
                                    getApplicationContext(),
                                    HospitalHome.class);
                            intent.putExtra("user_name", arr[0]);
                            startActivity(intent);
                        }
                        else{
                            Log.v("type", type);
                            Intent intent = new Intent(getApplicationContext(),
                                    DonorHome.class);
                            intent.putExtra("user_name", arr[0]);
                            startActivity(intent);
                        }






                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }
    });
4

1 に答える 1

1

if ステートメントの前にタイプをログに記録してみてください。どのようなタイプかを実際に見てみましょう。

のように:

 Log.i("Type", type);
 if (type.equals("0")) {
                        Log.v("type", type);
                        Intent intent = new Intent(
                                getApplicationContext(),
                                HospitalHome.class);
                        intent.putExtra("user_name", arr[0]);
                        startActivity(intent);
                    }

また、ログを記録するときは、final String TAG = "myActivity";を作成することをお勧めします。クラス属性として、次の方法でその TAG を追加します。Log.i(TAG, "thingIwanttolog");

于 2012-11-08T12:35:22.467 に答える