{"id":6058,"date":"2014-04-12T02:58:20","date_gmt":"2014-04-12T02:58:20","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/12\/android-runtime-exception-an-error-occur-while-executing-doinbackground-collection-of-common-programming-errors-2\/"},"modified":"2014-04-12T02:58:20","modified_gmt":"2014-04-12T02:58:20","slug":"android-runtime-exception-an-error-occur-while-executing-doinbackground-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/12\/android-runtime-exception-an-error-occur-while-executing-doinbackground-collection-of-common-programming-errors-2\/","title":{"rendered":"Android Runtime exception : An error occur while executing doinbackground-Collection of common programming errors"},"content":{"rendered":"<p>I am parsing online Xml using XmlPullParserFactory and showing the details in a listview. I have put the condition for checking internet, but sometimes it takes time to fetch data and crashes.The code which I am using is below.<\/p>\n<pre><code>      private void runningABackProcess() {\n      Handler mHandler = new Handler(Looper.getMainLooper());\n      Runnable myRunnable = new Runnable() {                        \n      public void run() {\n       try{\n             \/\/Thread.sleep(5000);\n\n         new DoSomeTask().execute();                           \n\n                  }catch(Exception e){}\n                           \/\/ myPd_ring.dismiss();\n              }\n           };\n           mHandler.post(myRunnable);\n\n    }\n         private class DoSomeTask extends AsyncTask\n     {\n\n\n        @Override\n         protected Void doInBackground(Void... arg0) {\n                        try { \n         isInternetPresent = icd.isConnectingToInternet\n         if(isInternetPresent){                             \n              URL url = new     URL(\"njhgjghjkjhkjl\");                                 \n              XmlPullParserFactory factory=XmlPullParserFactory.newInstance();  \n              XmlPullParser xpp=factory.newPullParser();      \n              xpp.setInput(getInputStream(url), \"UTF_8\");                                   \n              int eventType=xpp.getEventType(); \n              if(eventType!=XmlPullParser.END_DOCUMENT)\n                  {\n            if(eventType==XmlPullParser.START_DOCUMENT)     \n                 {       \n                 while(eventType!=XmlPullParser.END_DOCUMENT )              \n                  {              \n                              xpp_name=xpp.getName();                                   \n                      if((xpp_name!=null) ) \n                                {\n                                   --------------------\n                                   -------------------------\n                                }\n                            }\n                    }\n               }\n<\/code><\/pre>\n<p>and<\/p>\n<pre><code>      public InputStream getInputStream(URL url) {\n  try {  \n       InputStream str=null;\n       isInternetPresent=icd.isConnectingToInternet();\n      if(isInternetPresent)\n           {    \n         str=url.openConnection().getInputStream(); \n         if(str!= null)\n             {\n             return str; \n          }else{\n         new AlertDialogBox(getActivity()).show(getFragmentManager(),\"MyDialog\");\n          }\n    }else{\n    new AlertDialogBox(getActivity()).show(getFragmentManager(), \"MyDialog\");\n                            }\n                                return    str;              \n                            \/\/}\n                        } catch (IOException e) {\n\n                            return null;\n                          }\n\n                     }\n<\/code><\/pre>\n<p>Below is the erroe I am getting: <img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/sWhF7.png\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am parsing online Xml using XmlPullParserFactory and showing the details in a listview. I have put the condition for checking internet, but sometimes it takes time to fetch data and crashes.The code which I am using is below. private void runningABackProcess() { Handler mHandler = new Handler(Looper.getMainLooper()); Runnable myRunnable = new Runnable() { public [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6058","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6058","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6058"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6058\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6058"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6058"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6058"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}