我在MySql
中插入数据,数据插入成功。但是在成功操作后我无法Intent
到Activity
。{
这是我的代码:
public void registerfinish(View view) {
...
new finalRegister().execute();
}
class finalRegister extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
...
}
/**
* getting All products from url
* */
protected String doInBackground(String... args) {
List<NameValuePair> params = new ArrayList<NameValuePair>();
...
// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = null ;
try {
json = jsonParser.makeHttpRequest(url,
"GET", params);
} catch (JSONException e) {
e.printStackTrace();
}
// check for success tag
try {
// check log cat fro response
Log.d("Create Response", json.toString());
success = json.getInt(TAG_SUCCESS);
} catch (JSONException e) {
e.printStackTrace();
}
if (success == 1) {
// successfully created product
Intent i = new Intent(Register2ndStep.this, FinalScreen.class);
startActivity(i);
// closing this screen
//finish();
} else {
...
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
}
}
}
logcat的:
Caused by: java.lang.NullPointerException
at wolverine.example.com.btp_scientist.Register2ndStep$finalRegister.doInBackground(Register2ndStep.java:220)
at wolverine.example.com.btp_scientist.Register2ndStep$finalRegister.doInBackground(Register2ndStep.java:173)
Register2ndStep.java:220: Log.d("Create Response", json.toString())
Register2ndStep.java:173: class finalRegister extends AsyncTask<String, String, String>
答案 0 :(得分:0)
只需将您的意图代码移动到onPostExecute方法:
protected void onPostExecute(String file_url) {
Intent i = new Intent(Register2ndStep.this, FinalScreen.class);
startActivity(i);
pDialog.dismiss();
}