0

私は助けが必要です...、私はAndroidプログラミングの初心者です。エラーが発生する理由がわかりません。私がそれを実行すると、これはエラーです

com.androidTA.androidclient.LoginActivity$1.onClick(LoginActivity.java:55) で

詳細については、これは LoginActivity.java です

public class LoginActivity extends Activity implements OnClickListener{
    Button btnLogin;
    Button btnLinkToRegister;
    EditText inputEmail;
    EditText inputPassword;
    TextView loginErrorMsg;


    private static String KEY_SUCCESS ="success";
    private static String KEY_ERROR ="error";
    private static String KEY_ERROR_MSG ="error_msg";
    private static String KEY_UID ="uid";
    private static String KEY_NAME="name";
    private static String KEY_EMAIL="email";
    private static String KEY_CREATED_AT="created_at";

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);


         inputEmail = (EditText) findViewById(R.id.loginEmail);
         inputPassword = (EditText) findViewById(R.id.loginPassword);
         btnLogin = (Button) findViewById(R.id.btnLogin);
         btnLinkToRegister = (Button) findViewById(R.id.btnLinkToRegisterScreen);
         loginErrorMsg = (TextView) findViewById(R.id.login_error);


         btnLogin.setOnClickListener(new View.OnClickListener() {
             public void onClick(View view) {
             String email = inputEmail.getText().toString();
             String password = inputPassword.getText().toString();
             UserFunction userFunction = new UserFunction();
             JSONObject json = userFunction.loginUser(email, password);

             try {
                 if (json.getString(KEY_SUCCESS)!=null) {
                     loginErrorMsg.setText("");
                     String res = json.getString(KEY_SUCCESS); 
                     if(Integer.parseInt(res) == 1){

                         DatabaseHandler db = new      DatabaseHandler(getApplicationContext());
                         JSONObject json_user = json.getJSONObject("user");


                         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));                        


                         Intent dashboard = new Intent(getApplicationContext(), DashboardActivity.class);


                         dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                         startActivity(dashboard);


                         finish();
                     }
                     else{

                     loginErrorMsg.setText("Incorrect username/password");
                     }
                    }
                } 
                catch (JSONException e) {
                    e.printStackTrace();
                }
             }
         });



            btnLinkToRegister.setOnClickListener(new View.OnClickListener() {

                public void onClick(View view) {
                    Intent i = new Intent(getApplicationContext(),
                    RegisterActivity.class);
                    startActivity(i);
                    finish();
                }
         });
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

    }

}

これがログチャットです

07-17 12:19:38.818: W/KeyCharacterMap(320): No keyboard for id 0
07-17 12:19:38.818: W/KeyCharacterMap(320): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
07-17 12:22:56.667: W/System.err(320): java.net.SocketException: The operation timed out
07-17 12:22:56.697: W/System.err(320):  at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocketImpl(Native Method)
07-17 12:22:56.697: W/System.err(320):  at org.apache.harmony.luni.platform.OSNetworkSystem.connect(OSNetworkSystem.java:115)
07-17 12:22:56.707: W/System.err(320):  at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:244)
07-17 12:22:56.707: W/System.err(320):  at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
07-17 12:22:56.707: W/System.err(320):  at java.net.Socket.connect(Socket.java:1055)
07-17 12:22:56.717: W/System.err(320):  at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
07-17 12:22:56.717: W/System.err(320):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
07-17 12:22:56.717: W/System.err(320):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
07-17 12:22:56.717: W/System.err(320):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
07-17 12:22:56.727: W/System.err(320):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
07-17 12:22:56.727: W/System.err(320):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
07-17 12:22:56.737: W/System.err(320):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
07-17 12:22:56.737: W/System.err(320):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
07-17 12:22:56.737: W/System.err(320):  at library.JSONParser.getJSONFromUrl(JSONParser.java:40)
07-17 12:22:56.751: W/System.err(320):  at library.UserFunction.loginUser(UserFunction.java:37)
07-17 12:22:56.757: W/System.err(320):  at com.androidTA.androidclient.LoginActivity$1.onClick(LoginActivity.java:51)
07-17 12:22:56.757: W/System.err(320):  at android.view.View.performClick(View.java:2408)
07-17 12:22:56.757: W/System.err(320):  at android.view.View$PerformClick.run(View.java:8816)
07-17 12:22:56.757: W/System.err(320):  at android.os.Handler.handleCallback(Handler.java:587)
07-17 12:22:56.768: W/System.err(320):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-17 12:22:56.768: W/System.err(320):  at android.os.Looper.loop(Looper.java:123)
07-17 12:22:56.768: W/System.err(320):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-17 12:22:56.768: W/System.err(320):  at java.lang.reflect.Method.invokeNative(Native Method)
07-17 12:22:56.768: W/System.err(320):  at java.lang.reflect.Method.invoke(Method.java:521)
07-17 12:22:56.777: W/System.err(320):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-17 12:22:56.777: W/System.err(320):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-17 12:22:56.787: W/System.err(320):  at dalvik.system.NativeStart.main(Native Method)
07-17 12:22:56.817: E/Buffer Error(320): Error Convertine Resultjava.lang.NullPointerException
07-17 12:22:56.837: E/JSON PARSER(320): Error parsing dataorg.json.JSONException: End of input at character 0 of 
07-17 12:22:56.847: D/AndroidRuntime(320): Shutting down VM
07-17 12:22:56.847: W/dalvikvm(320): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-17 12:22:56.877: E/AndroidRuntime(320): FATAL EXCEPTION: main
07-17 12:22:56.877: E/AndroidRuntime(320): java.lang.NullPointerException
07-17 12:22:56.877: E/AndroidRuntime(320):  at com.androidTA.androidclient.LoginActivity$1.onClick(LoginActivity.java:55)
07-17 12:22:56.877: E/AndroidRuntime(320):  at android.view.View.performClick(View.java:2408)
07-17 12:22:56.877: E/AndroidRuntime(320):  at android.view.View$PerformClick.run(View.java:8816)
07-17 12:22:56.877: E/AndroidRuntime(320):  at android.os.Handler.handleCallback(Handler.java:587)
07-17 12:22:56.877: E/AndroidRuntime(320):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-17 12:22:56.877: E/AndroidRuntime(320):  at android.os.Looper.loop(Looper.java:123)
07-17 12:22:56.877: E/AndroidRuntime(320):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-17 12:22:56.877: E/AndroidRuntime(320):  at java.lang.reflect.Method.invokeNative(Native Method)
07-17 12:22:56.877: E/AndroidRuntime(320):  at java.lang.reflect.Method.invoke(Method.java:521)
07-17 12:22:56.877: E/AndroidRuntime(320):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-17 12:22:56.877: E/AndroidRuntime(320):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-17 12:22:56.877: E/AndroidRuntime(320):  at dalvik.system.NativeStart.main(Native Method)
07-17 12:24:15.027: I/Process(320): Sending signal. PID: 320 SIG: 9

解決策をありがとう... :)

4

3 に答える 3

0

まず、リムーバー

OnClickListener を実装します

onclickリスナーをボタンに直接追加する場合、このメソッドも実装する必要はありません

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

}

この行を変更

  Intent i = new Intent(getApplicationContext(),RegisterActivity.class);

  Intent i = new Intent(LoginActivity.this,RegisterActivity.class);
于 2013-07-17T06:32:46.427 に答える
0

loginUser(email, password)おそらくメソッド内で接続がタイムアウトしています。デバイスが接続されていて、サーバーがリクエストに応答していることを確認してください。を呼び出すコードを確認してください。null がgetJSONFromUrl返されます。

于 2013-07-17T06:34:47.397 に答える
0
@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    if (v == btnLogin) {
        // TODO what you want with btnlogin onclicklistener
    } else if (v == btnLinkToRegister) {
        // TODO what you want with btnLinkToRegister onclicklistener
    }
}
于 2013-07-17T06:34:56.020 に答える