你好我的android应用程序有问题...应用程序正在android studio上工作,他们停止工作显示此错误..
Error parsing data org.json.JSONException: End of input at character 0 of
03-29 17:38:39.180 890-890/com.example.cinema D/AndroidRuntime﹕ Shutting down VM
03-29 17:38:39.180 890-890/com.example.cinema W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb3b04ba8)
03-29 17:38:39.220 890-890/com.example.cinema E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.cinema, PID: 890
java.lang.NullPointerException
at com.example.cinema.MainActivity$1.onClick(MainActivity.java:63)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
03-29 17:38:44.320 890-890/com.example.cinema I/Process﹕ Sending signal. PID: 890 SIG: 9
主要活动代码如下
public class MainActivity extends Activity {
EditText etemail, etpass;
Button login, register;
TextView tError;
private static String KEY_SUCCESS = "success";
private static final String KEY_REFERRED_AS = "referred_as";
private static final String KEY_EMAIL = "email";
private static final String KEY_CARD = "Card";
private static final String KEY_ADDRESS = "address";
private static final String KEY_CONTACT_NO = "contact_no";
private static final String KEY_ID = "id";
private static final String KEY_DATEOFBIRTH = "DateOfBirth";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setting default screen to sign_in.xml
setContentView(R.layout.activity_main);
etemail = (EditText) findViewById(R.id.emailAddress);
etpass = (EditText) findViewById(R.id.password);
tError = (TextView) findViewById(R.id.error);
login = (Button) findViewById(R.id.login);
register = (Button) findViewById(R.id.reg);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view){
String email = etemail.getText().toString();
String password = etpass.getText().toString();
UserFunctions userFunction = new UserFunctions();
Log.d("Button", "Login");
JSONObject json = userFunction.loginUser(email, password);
try {
if (json.getString(KEY_SUCCESS) != null) {
return;
}
tError.setText("login");
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_REFERRED_AS),json_user.getString(KEY_EMAIL),json_user.getString(KEY_CARD),
json_user.getString(KEY_DATEOFBIRTH),json_user.getString(KEY_ADDRESS),
json_user.getString(KEY_CONTACT_NO),json_user.getString(KEY_ID));
// Launch Dashboard Screen
Intent intent = new Intent(getApplicationContext(), Home.class);
// Close all views before launching Dashboard
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
// Close Login Screen
finish();
}else{
// Error in login
tError.setText("Incorrect username/password");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(),Register.class);
startActivity(i);
}
});
}
}