私はこのバグを修正しようとしますが、なぜnullpointerjson
があり、成功を返すことができるのかを知っています。
public class Login extends Activity {
public TextView loginErrorMsg;
private ProgressDialog progressDialog;
private JSONObject jsonResult;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bus_login);
//findViewById
}
public void btnLogin_OnClick(View v) {
new LoginTask().execute();
}
class LoginTask extends AsyncTask<String, String, JSONObject> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(Login.this);
progressDialog.setMessage("Logging in...");
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(true);
progressDialog.show();
}
protected JSONObject doInBackground(String... args) {
// TODO Auto-generated method stub
String uname = inputUserId.getText().toString();
String password =inputPassword.getText().toString();
UserFunctions vehicleFunction = new UserFunctions();
jsonResult = vehicleFunction.loginVehicle(uname, password);
return jsonResult;
}
protected void onPostExecute(JSONObject jsonResult) {
// dismiss the dialog once done
progressDialog.dismiss();
try {
int success = jsonResult.getInt("success");
if (success == 1) {
loginErrorMsg.setText("success");
} else{
loginErrorMsg.setText("Fail");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public JSONObject loginVehicle(String vehicleId, String password){
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", login_tag));
params.add(new BasicNameValuePair("vehicleId", vehicleId));
params.add(new BasicNameValuePair("password", password));
JSONObject json = jsonParser.getJSONFromUrl(loginVehicleURL, params);
return json;
}
01-27 23:44:12.438: W/System.err(2121): java.lang.NullPointerException
01-27 23:44:12.438: W/System.err(2121): at com.ptms.Bus_Login$LoginTask.onPostExecute(Bus_Login.java:79)
01-27 23:44:12.448: W/System.err(2121): at com.ptms.Bus_Login$LoginTask.onPostExecute(Bus_Login.java:1)
01-27 23:44:12.448: W/System.err(2121): at android.os.AsyncTask.finish(AsyncTask.java:602)
01-27 23:44:12.458: W/System.err(2121): at android.os.AsyncTask.access$600(AsyncTask.java:156)
01-27 23:44:12.458: W/System.err(2121): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:615)
01-27 23:44:12.458: W/System.err(2121): at android.os.Handler.dispatchMessage(Handler.java:99)
01-27 23:44:12.458: W/System.err(2121): at android.os.Looper.loop(Looper.java:137)
01-27 23:44:12.458: W/System.err(2121): at android.app.ActivityThread.main(ActivityThread.java:4424)
01-27 23:44:12.458: W/System.err(2121): at java.lang.reflect.Method.invokeNative(Native Method)
01-27 23:44:12.458: W/System.err(2121): at java.lang.reflect.Method.invoke(Method.java:511)
01-27 23:44:12.458: W/System.err(2121): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-27 23:44:12.458: W/System.err(2121): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-27 23:44:12.458: W/System.err(2121): at dalvik.system.NativeStart.main(Native Method)