执行 doinBackground()
时出错。
class PostComment extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(AddComment.this);
pDialog.setMessage("Attempting login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
//postData("deepika");
}
@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
// Check for success tag
int success;
String post_title = intime.getText().toString();
String post_message = outtime.getText().toString();
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(AddComment.this);
String post_username = sp.getString("username", "anon");
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", post_username));
params.add(new BasicNameValuePair("intime", post_title));
params.add(new BasicNameValuePair("outtime", post_message));
Log.d("request!", "starting");
// getting product details by making HTTP request
JSONObject json = jsonParser.makeHttpRequest(POST_COMMENT_URL, "POST",
params);
//JSONObject json1 = jsonParser.makeHttpRequest("http://192.168.10.30/webservice/comments.php", "POST",
// params);
// check your log for json response
Log.d("Login attempt", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Attendence Marked!", json.toString());
//finish();
return json.getString(TAG_MESSAGE);
}else{
Log.d("Attendence Failure!", json.getString(TAG_MESSAGE));
return json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog once product deleted
pDialog.dismiss();
finish();
if (file_url != null) {
Toast.makeText(AddComment.this, file_url, Toast.LENGTH_LONG).show();
}
}
}
这是错误日志:
11-05 05:03:20.171:E/Android runtime(3171):致命异常:async task # 1 < br > 11-05 05:03:20.171:E/Android runtime(3171):Process:com . example . MySQL test,PID:3171 < br > 11-05 05:03:20.171:E/Android runtime(3171):Java . lang . runtime EXCEPTION:An
在点击监听器中执行此操作
mSubmit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View vw) {
String post_title = intime.getText().toString();
String post_message = outtime.getText().toString();
new PostComment(post_title,post_message).execute();
}
});
and in the asynch task change this
class PostComment extends AsyncTask<String, String, String> {
String response = "";
String post_title ="";
String post_message="";
// Check for success tag
int success;
public PostComment(String title,String msg) {
post_title = title;
post_message = msg;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(AddComment.this);
pDialog.setMessage("Attempting login...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
//postData("deepika");
}
@Override
protected String doInBackground(String... args) {
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(AddComment.this);
String post_username = sp.getString("username", "anon");
try {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", post_username));
params.add(new BasicNameValuePair("intime", post_title));
params.add(new BasicNameValuePair("outtime", post_message));
Log.d("request!", "starting");
// getting product details by making HTTP request
JSONObject json = jsonParser.makeHttpRequest(POST_COMMENT_URL, "POST",
params);
//JSONObject json1 = jsonParser.makeHttpRequest("http://192.168.10.30/webservice/comments.php", "POST",
// params);
// check your log for json response
Log.d("Login attempt", json.toString());
// json success tag
success = json.getInt(TAG_SUCCESS);
if (success == 1) {
Log.d("Attendence Marked!", json.toString());
response = json.getString(TAG_MESSAGE);
}else{
Log.d("Attendence Failure!", json.getString(TAG_MESSAGE));
response = json.getString(TAG_MESSAGE);
}
} catch (JSONException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
return response;
}
protected void onPostExecute(String file_url) {
// dismiss the dialog once product deleted
pDialog.dismiss();
if (file_url != null) {
Toast.makeText(AddComment.this, file_url, Toast.LENGTH_LONG).show();
}
}
}
java.lang.RuntimeException:执行doInBackground()E/Android runtime(695)时出错:at Android . OS . async task $ 3 . done(async task . Java:200)E/Android runtime(695):at Java . util . concurrent . future task $
活动: 类 updateTwitterStatus extends AsyncTask { 这就是 LogCat 06-05 18:00:26.696: E/AndroidRuntime(1516): 致命异常: AsyncTask #2 06-05 18:00:26.696: E/AndroidRuntime(1516): java.lang.RuntimeException: 执行 doInB
我做了一个应用程序登录,一切都是正常的昨天,但今天android工作室给了我这个错误 {08-03 14:29:07.894 137 03-14015/Complete.Lyne.MyApplication E/AndroidRuntime:致命异常:AsyncTask#1进程:Complete.Lyne.MyApplication,PID:13703 java.lang.RuntimeExcep
我在android设备上构建代码时出错了。这是错误报告 05-17 09:47:16.035 17982-18134/com . example . ckw . mapku E/Android runtime:致命异常:async task # 1 05-17 09:47:16.035 17982-18134/com . example . mapku E/Android runtime:Proc
我在android设备上构建代码时出错。这是错误报告 致命异常:AsyncTask#1进程:com。实例冈图,PID:1248爪哇。lang.RuntimeException:在android上执行doInBackground()时出错。操作系统。异步任务3美元。在java上完成(AsyncTask.java:304)。util。同时发生的未来任务。在java完成(FutureTask.java: