私は一日中、関連する研究でこの問題を解決しようとしました. アプリケーションをエミュレーターで実行できますが、Android デバイス、つまり samsung 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;
}
}