我一整天都在尝试通过相关研究来解决这个问题。我可以在模拟器中运行我的应用程序,但不能在 android 设备中运行,即三星 Galaxy ace 2。我在 logcat 中得到以下错误。非常感谢您的帮助。谢谢!
03-20 18:40:07.340: E/AndroidRuntime(15785): FATAL EXCEPTION: main
03-20 18:40:07.340: E/AndroidRuntime(15785): java.lang.NullPointerException
03-20 18:40:07.340: E/AndroidRuntime(15785): at com.dorji.finalproject.LoginLayout$MyAsyncTask.onPostExecute(LoginLayout.java:87)
03-20 18:40:07.340: E/AndroidRuntime(15785): at com.dorji.finalproject.LoginLayout$MyAsyncTask.onPostExecute(LoginLayout.java:1)
03-20 18:40:07.340: E/AndroidRuntime(15785): at android.os.AsyncTask.finish(AsyncTask.java:417)
03-20 18:40:07.340: E/AndroidRuntime(15785): at android.os.AsyncTask.access$300(AsyncTask.java:127)
03-20 18:40:07.340: E/AndroidRuntime(15785): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
03-20 18:40:07.340: E/AndroidRuntime(15785): at android.os.Handler.dispatchMessage(Handler.java:99)
03-20 18:40:07.340: E/AndroidRuntime(15785): at android.os.Looper.loop(Looper.java:130)
03-20 18:40:07.340: E/AndroidRuntime(15785): at android.app.ActivityThread.main(ActivityThread.java:3691)
03-20 18:40:07.340: E/AndroidRuntime(15785): at java.lang.reflect.Method.invokeNative(Native Method)
03-20 18:40:07.340: E/AndroidRuntime(15785): at java.lang.reflect.Method.invoke(Method.java:507)
03-20 18:40:07.340: E/AndroidRuntime(15785): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
03-20 18:40:07.340: E/AndroidRuntime(15785): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:670)
03-20 18:40:07.340: E/AndroidRuntime(15785): at dalvik.system.NativeStart.main(Native Method)
主要错误代码:
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new newAsyncTask().execute();
}
});
}
private class newAsyncTask extends AsyncTask<Void, Void, Void>
{
ProgressDialog Dialog;
String user = username.getText().toString();
String pass = password.getText().toString();
@Override
protected void onPreExecute() {
Dialog = ProgressDialog.show(Login.this, "processing..", "data is Loading...");
}
@Override
protected void onPostExecute(Void result) {
if(res.equals("1")){
if (Dialog.isShowing()) {
Dialog.dismiss();
}
} else{
error.setText("Sorry, wrong username and password");
Dialog.dismiss();
}
}
@Override
protected Void doInBackground(Void... params) {
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("username", user));
postParameters.add(new BasicNameValuePair("password", pass));
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://10.0.2.2:8080/MainServer/LoginResponse", postParameters);
res=response.toString();
res= res.replaceAll("\\s+","");
Bundle bundle = new Bundle();
bundle.putString("param1", user);
bundle.putString("param2", pass);
Intent newIntent = new Intent(getApplicationContext(), MainActivity.class);
newIntent.putExtras(bundle);
startActivityForResult(newIntent, 0);
} catch (Exception e) {
System.out.println(e.toString());
}
return null;
}
}