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 8954765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:23:04+00:00 2026-06-15T14:23:04+00:00

I try to load xml file in my Android application. When run userList.setInput(xmlUrl.openStream(), null);

  • 0

I try to load xml file in my Android application. When run userList.setInput(xmlUrl.openStream(), null); I see message “The Application has stoped unexpectedly”.

URL xmlUrl = null;
                String tmp = "";
                 Log.d(LOG_TAG, "BUTTON IS ON");

                try {
                    xmlUrl = new URL("http://55.55.55.55/1.xml");
                    Log.d(LOG_TAG, "1");
                } catch (MalformedURLException e) {             
                    e.printStackTrace();
                }
                XmlPullParser userList = null;
                try {
                    userList = XmlPullParserFactory.newInstance().newPullParser();
                    Log.d(LOG_TAG, "2");
                } catch (XmlPullParserException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                try {
                    userList.setInput(xmlUrl.openStream(), null);
                    Log.d(LOG_TAG, "3");
                } catch (XmlPullParserException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Log.d(LOG_TAG, "3x");
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Log.d(LOG_TAG, "3y");
                }

What I do wrong?
In log I see:

12-07 11:53:33.712: DEBUG/dalvikvm(263): GC_EXPLICIT freed 3K, 11% free 17590K/19719K, paused 3ms+4ms
12-07 11:53:33.892: INFO/ActivityManager(88): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.hotdog_master/.MainActivity } from pid 263
12-07 11:53:33.892: WARN/WindowManager(88): Failure taking screenshot for (230x135) to layer 21005
12-07 11:53:33.952: INFO/ActivityManager(88): Start proc com.example.hotdog_master for activity com.example.hotdog_master/.MainActivity: pid=778 uid=10036 gids={3003}
12-07 11:53:35.682: INFO/ActivityManager(88): Displayed com.example.hotdog_master/.MainActivity: +1s746ms
12-07 11:53:36.714: DEBUG/dalvikvm(263): GC_EXPLICIT freed 7K, 11% free 17592K/19719K, paused 3ms+4ms
12-07 11:53:39.112: DEBUG/AndroidRuntime(778): Shutting down VM
12-07 11:53:39.112: WARN/dalvikvm(778): threadid=1: thread exiting with uncaught exception (group=0x40014760)
12-07 11:53:39.122: ERROR/AndroidRuntime(778): FATAL EXCEPTION: main
12-07 11:53:39.122: ERROR/AndroidRuntime(778): android.os.NetworkOnMainThreadException
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1077)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at dalvik.system.BlockGuard$WrappedNetworkSystem.connect(BlockGuard.java:368)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:208)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:431)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at java.net.Socket.connect(Socket.java:901)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:75)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:304)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:292)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:274)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1038)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:523)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at java.net.URL.openStream(URL.java:645)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at com.example.hotdog_master.MainActivity.Xmlworker(MainActivity.java:72)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at com.example.hotdog_master.MainActivity$1.onClick(MainActivity.java:37)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at android.view.View.performClick(View.java:3110)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at android.view.View$PerformClick.run(View.java:11934)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at android.os.Handler.handleCallback(Handler.java:587)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at android.os.Looper.loop(Looper.java:132)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at android.app.ActivityThread.main(ActivityThread.java:4123)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at java.lang.reflect.Method.invokeNative(Native Method)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at java.lang.reflect.Method.invoke(Method.java:491)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
12-07 11:53:39.122: ERROR/AndroidRuntime(778):     at dalvik.system.NativeStart.main(Native Method)
12-07 11:53:39.142: WARN/ActivityManager(88):   Force finishing activity com.example.hotdog_master/.MainActivity
12-07 11:53:39.142: WARN/WindowManager(88): Failure taking screenshot for (230x135) to layer 21010
12-07 11:53:39.662: WARN/ActivityManager(88): Activity pause timeout for ActivityRecord{407709a8 com.example.hotdog_master/.MainActivity}
12-07 11:53:50.532: WARN/ActivityManager(88): Activity destroy timeout for ActivityRecord{407709a8 com.example.hotdog_master/.MainActivity}
  • 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-15T14:23:06+00:00Added an answer on June 15, 2026 at 2:23 pm

    There are two Solution of this Problem but first one is great solution.

    1) Don’t write network call in Main UI Thread, Use Async Task for that.

    2) Write below code into your MainActivity file after setContentView(R.layout.activity_main); but this is not proper way.

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }
    

    And below import statement into your java file.

    import android.os.StrictMode;
    

    And see below link for more information.

    Caused by: android.os.NetworkOnMainThreadException

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've developed an Android application but when I try to run it in the
I have a huge XML file (114 KB/1719 lines; see the error message below
I have an XML file. When I try to load it using .LOAD methods,
I need to load an xml file as String in android so I can
I try to use XmlDocument to load xml file. However, the codes alway return
I have a big 400kb xml file. When i try to load it by
I try to load the customview class that is inside my mainclass in xml.
I have an XML document that I load in and try to search with
I try to load files in different categories according to theis file name. Till
I'm trying to load an xml file into the interface and there may be

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.