我需要帮助...,我是 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
非常感谢您的解决方案... :)