FATAL EXCEPTION : Asyntask#5 Runtime Exception Android

妖精的绣舞 提交于 2019-12-13 04:09:43

问题


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

回答1:


     @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.



来源:https://stackoverflow.com/questions/14556813/fatal-exception-asyntask5-runtime-exception-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!