Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8811245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:18:53+00:00 2026-06-14T03:18:53+00:00

I have an app that has an xml Dom parser in it. The parser

  • 0

I have an app that has an xml Dom parser in it. The parser activity is activated by a button in another fragment. When i run the app it runs fine on Gingerbread, but on Honeycomb and up to Jelly Bean it force closes every time. Here is the class information and the log cat file for when it force closes. IF anyone has any ideas on what is causing this please let me know.

Class I’m trying to launch

 public class CustomizedListView extends SherlockActivity {
// All static variables
static final String URL = "http://treymorgan.net/feed";
// XML node keys
static final String KEY_ID = "channel"; // parent node 
static final String KEY_ITEM = "item";
static final String KEY_TITLE = "title";
static final String KEY_PUB_DATE = "pubDate";
static final String KEY_LINK = "link";

ListView list;
LazyAdapter adapter;

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // app icon in action bar clicked; go home
                    Intent intent = new Intent(this, MainActivity.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                    return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ActionBar bar = getSupportActionBar();
    bar.setDisplayHomeAsUpEnabled(true);



    final ArrayList<HashMap<String, String>> songsList = new ArrayList<HashMap<String, String>>();

    XMLParser parser = new XMLParser();
    String xml = parser.getXmlFromUrl(URL); // getting XML from URL
    Document doc = parser.getDomElement(xml); // getting DOM element

    NodeList nl = doc.getElementsByTagName(KEY_ITEM);
    // looping through all song nodes <song>
    for (int i = 0; i < nl.getLength(); i++) {
        // creating new HashMap
        HashMap<String, String> map = new HashMap<String, String>();
        Element e = (Element) nl.item(i);
        // adding each child node to HashMap key => value
        map.put(KEY_ITEM, parser.getValue(e, KEY_ITEM));
        map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
        map.put(KEY_PUB_DATE, parser.getValue(e, KEY_PUB_DATE));
        map.put(KEY_LINK, parser.getValue(e, KEY_LINK));

        // adding HashList to ArrayList
        songsList.add(map);
    }


    list=(ListView)findViewById(R.id.list);

    // Getting adapter by passing xml data ArrayList
    adapter=new LazyAdapter(this, songsList);        
    list.setAdapter(adapter);


    // Click event for single list row
    list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            Uri uriUrl = Uri.parse(songsList.get(position).get(KEY_LINK));  
            Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);  
            startActivity(launchBrowser);  



             }

    });
}   
}

Log Cat

08-29 03:28:48.603: E/AndroidRuntime(658): FATAL EXCEPTION: main
08-29 03:28:48.603: E/AndroidRuntime(658): java.lang.RuntimeException: Unable to start        activity ComponentInfo{com.threesixteenapps.treymorgan/com.threesixteenapps.treymorgan.CustomizedListView}: android.os.NetworkOnMainThreadException
08-29 03:28:48.603: E/AndroidRuntime(658):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
08-29 03:28:48.603: E/AndroidRuntime(658):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
08-29 03:28:48.603: E/AndroidRuntime(658):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
08-29 03:28:48.603: E/AndroidRuntime(658):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
08-29 03:28:48.603: E/AndroidRuntime(658):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-29 03:28:48.603: E/AndroidRuntime(658):  at android.os.Looper.loop(Looper.java:137)
08-29 03:28:48.603: E/AndroidRuntime(658):  at android.app.ActivityThread.main(ActivityThread.java:4424)
08-29 03:28:48.603: E/AndroidRuntime(658):  at java.lang.reflect.Method.invokeNative(Native Method)
08-29 03:28:48.603: E/AndroidRuntime(658):  at java.lang.reflect.Method.invoke(Method.java:511)
08-29 03:28:48.603: E/AndroidRuntime(658):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-29 03:28:48.603: E/AndroidRuntime(658):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-29 03:28:48.603: E/AndroidRuntime(658):  at dalvik.system.NativeStart.main(Native Method)
08-29 03:28:48.603: E/AndroidRuntime(658): Caused by: android.os.NetworkOnMainThreadException
08-29 03:28:48.603: E/AndroidRuntime(658):  at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
08-29 03:28:48.603: E/AndroidRuntime(658):  at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
08-29 03:28:48.603: E/AndroidRuntime(658):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
08-29 03:28:48.603: E/AndroidRuntime(658):  at java.net.InetAddress.getAllByName(InetAddress.java:220)
08-29 03:28:48.603: E/AndroidRuntime(658):  at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:137)
08-29 03:28:48.603: E/AndroidRuntime(658):  at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
08-29 03:28:48.603: E/AndroidRuntime(658):  at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
08-29 03:28:48.603: E/AndroidRuntime(658):  at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
08-29 03:28:48.603: E/AndroidRuntime(658):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
08-29 03:28:48.603: E/AndroidRuntime(658):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
08-29 03:28:48.603: E/AndroidRuntime(658):  at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
08-29 03:28:48.603: E/AndroidRuntime(658):  at com.threesixteenapps.treymorgan.XMLParser.getXmlFromUrl(XMLParser.java:45)
08-29 03:28:48.603: E/AndroidRuntime(658):  at com.threesixteenapps.treymorgan.CustomizedListView.onCreate(CustomizedListView.java:64)
08-29 03:28:48.603: E/AndroidRuntime(658):  at android.app.Activity.performCreate(Activity.java:4465)
08-29 03:28:48.603: E/AndroidRuntime(658):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-29 03:28:48.603: E/AndroidRuntime(658):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
08-29 03:28:48.603: E/AndroidRuntime(658):  ... 11 more

If any more info is needed i will gladly provide it for you. Thank you for your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:18:55+00:00Added an answer on June 14, 2026 at 3:18 am

    Android 3.0 and higher won’t allow you to do any networking tasks in the ui-thread (see this post).
    The solution is to implement an AsyncTask or possibly a Loader.

    Edit: I made a quick example of how you can implement an AsyncTask in your Activity.
    I removed some parts or replaced them with comments to keep it reasonably short. Just merge it with your code and it should work fine (replace MyActivity with your own etc).

    public class MyActivity extends Activity{
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            //super onCreate, setup your content, actionbar etc.
    
            AsyncTask getxml = new MyAsyncTask();
            getxml.execute(URL);
        }
    
        private class MyAsyncTask extends AsyncTask<String, Integer, Void>{
            private static final int RESULT_GOT_XML = 1;
            private static final int RESULT_FAILED = 0;
            private ArrayList<HashMap<String, String>> asyncList;
            public MyAsyncTask(){
                asyncList = new ArrayList<HashMap<String, String>>();
            }
    
            @Override
            protected Integer doInBackground(String... url) {
    
                try{
                    XMLParser parser = new XMLParser();
                    String xml = parser.getXmlFromUrl(url[0]);
                    Document doc = parser.getDomElement(xml);
    
                    NodeList nl = doc.getElementsByTagName(KEY_ITEM);
                    for (int i = 0; i < nl.getLength(); i++) {
                        //...perform the parsing and add to list:
                        asyncList.add(map);
                    }
                }catch(IOException e){
                    Log.e("MyAsync", "could not complete xml retrieval/parsing", e);
                    return RESULT_FAILED;
                }
                return RESULT_GOT_XML;
            }
    
            @Override
            protected void onPostExecute(Integer result) {
                switch (result) {
                case RESULT_FAILED:
                    Toast.makeText(MyActivity.this, "Could not get data", Toast.LENGTH_SHORT).show();
                    break;
                case RESULT_GOT_XML:
                    songsList.addAll(asyncList);
                    list=(ListView)findViewById(R.id.list);
                    adapter=new LazyAdapter(this, songsList);        
                    list.setAdapter(adapter);
    
                    list.setOnItemClickListener(yourclicklistener);
                default:
                    Log.wtf("MyAsync","got unexpected result: "+result);
                    break;
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Spring (3.1.) app that has a large app-context.xml file. There is
I have an app that has 2 tabs. Each tab loads an xml file
I have a web service app that has an xml file with Oracle connection
I have an app, that has an Activity that uses a ScrollView . I
Have an app that has listings - think classified ads - and each listing
I have an app that has different names for different languages. How do I
I have an app that has a centre view with two views off to
I have an app that has a tabbar at the bottom. When I select
I have an app that has a TableView, NavigationView and TabBar running together. There
I have an app that has a list of items. My customer prefers to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.