致命异常:Asyntask#5 Runtime Exception Android

时间:2013-01-28 06:47:13

标签: android httpresponse

此代码有时可行,但很遗憾停止工作。  我没有在后台更改任何内容(UI)。

给出了以下错误。

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();}  }

1 个答案:

答案 0 :(得分:0)

     @Override
    protected void onPostExecute(String result) {
    // super.onPostExecute(result);

       Log.e("OnPostExecute",result);
       try {
                dialog.dismiss();
                dialog = null;
            } catch (Exception e) {
                e.getMessage();
            }


    }

试试这一跳对你有帮助。