本文介绍了致命异常:Asyntask#5运行时异常的Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这code,有时作品和不幸的是停止工作。
我没有改变任何背景(UI)。
给出follwing错误。
6月1日至28日:42:53.060:E / AndroidRuntime(4993):致命异常:AsyncTask的#1
6月1日至28日:42:53.060:E / AndroidRuntime(4993):了java.lang.RuntimeException:执行doInBackground发生错误()
6月1日至28日:42:53.060:E / AndroidRuntime(4993):在android.os.AsyncTask $ 3.done(AsyncTask.java:299)
6月1日至28日:42:53.060:E / AndroidRuntime(4993):在java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
6月1日至28日:42:53.060:E / AndroidRuntime(4993):在java.util.concurrent.FutureTask.setException(FutureTask.java:219)
6月1日至28日:42:53.060:E / AndroidRuntime(4993):在java.util.concurrent.FutureTask.run(FutureTask.java:239)
6月1日至28日:42:53.060:E / AndroidRuntime(4993):在android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:230)
6月1日至28日:42:53.060:E / AndroidRuntime(4993):在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) 而且还可以请你解释一下如何得到Respose当我从TIBCO BE recieving Respose的事件。它与具有属性(状态)事件答复。
在onCreateBudle
新MyTask()执行(U)。
startActivity(新意图(AddUserActivity.this,InputActivity.class));
ProgressDialog对话框;
@覆盖
在preExecute保护无效(){
// TODO自动生成方法存根
super.on preExecute();
对话框= ProgressDialog.show(AddUserActivity.this,,
用户注册......); }
@覆盖
保护字符串doInBackground(字符串... URI){
字符串responseString = NULL; HttpClient的HttpClient的=新DefaultHttpClient();
HTT presponse响应;
的HttpParams PARAMS; 尝试{
响应= httpclient.execute(新HTTPGET(URI [0]));
状态行状态行= response.getStatusLine(); 如果(statusLine.getStatus code()== HttpStatus.SC_OK){
ByteArrayOutputStream出=新ByteArrayOutputStream();
。response.getEntity()的writeTo(出); 。responseString = response.getEntity()的getContent()的toString(); / * PARAMS = response.getParams(); responseString =(字符串)params.getParameter(状态); * /
out.close(); }其他{
//关闭连接。
。response.getEntity()的getContent()close()方法。
抛出新IOException异常(statusLine.getReasonPhrase());
}
}赶上(ClientProtocolException E){
// TODO处理问题..
}赶上(IOException异常五){
// TODO处理问题..
} 返回responseString;
} @覆盖
保护无效onPostExecute(字符串结果){
super.onPostExecute(结果); Log.e(OnPostExecute,结果); dialog.dismiss(); Toast.makeText(AddUserActivity.this,用户Registerd,Toast.LENGTH_LONG).show();}}
解决方案
@覆盖
保护无效onPostExecute(字符串结果){
// super.onPostExecute(结果); Log.e(OnPostExecute,结果);
尝试{
dialog.dismiss();
对话框= NULL;
}赶上(例外五){
e.getMessage();
}
}
试试这个跳了对您有所帮助。
This code sometimes works and Unfortunately stopped working. I am not changing anything(UI) in background.
gives follwing error.
01-28 06:42:53.060: E/AndroidRuntime(4993): FATAL EXCEPTION: AsyncTask #1
01-28 06:42:53.060: E/AndroidRuntime(4993): java.lang.RuntimeException: An error occured while executing doInBackground()
01-28 06:42:53.060: E/AndroidRuntime(4993): at android.os.AsyncTask$3.done(AsyncTask.java:299)
01-28 06:42:53.060: E/AndroidRuntime(4993): at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
01-28 06:42:53.060: E/AndroidRuntime(4993): at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
01-28 06:42:53.060: E/AndroidRuntime(4993): at java.util.concurrent.FutureTask.run(FutureTask.java:239)
01-28 06:42:53.060: E/AndroidRuntime(4993): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
01-28 06:42:53.060: E/AndroidRuntime(4993): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
And also could you please explain how to get Respose when i am recieving Respose as Event from TIBCO BE. it is replying with event with properties (Status).
IN onCreateBudle new MyTask().execute(u); startActivity(new Intent(AddUserActivity.this,InputActivity.class));
ProgressDialog dialog;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
dialog = ProgressDialog.show(AddUserActivity.this, "",
"User is Registering...");
}
@Override
protected String doInBackground(String... uri) {
String responseString = null;
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
HttpParams params;
try {
response = httpclient.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
responseString = response.getEntity().getContent().toString();
/*params = response.getParams();
responseString = (String) params.getParameter("Status");*/
out.close();
} else {
// Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
// TODO Handle problems..
} catch (IOException e) {
// TODO Handle problems..
}
return responseString;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Log.e("OnPostExecute",result);
dialog.dismiss();
Toast.makeText(AddUserActivity.this, "User Registerd", Toast.LENGTH_LONG).show();} }
解决方案
@Override
protected void onPostExecute(String result) {
// super.onPostExecute(result);
Log.e("OnPostExecute",result);
try {
dialog.dismiss();
dialog = null;
} catch (Exception e) {
e.getMessage();
}
}
try with this hop its helpful to you.
这篇关于致命异常:Asyntask#5运行时异常的Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!