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

  • Home
  • SEARCH
  • 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 770041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:26:03+00:00 2026-05-14T18:26:03+00:00

I have a weird issue. I receive the following error that causes a force-close:

  • 0

I have a weird issue. I receive the following error that causes a force-close:

org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: no element found at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:508)
at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:467)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:329)
at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:286)

After clicking the Force Close button, the Activity is recreated and the parsing completes without a hitch. I’m using the following code snippet inside doInBackground of an AsyncTask:

URL serverAddress = new URL(url[0]);

HttpURLConnection connection = (HttpURLConnection) serverAddress.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setReadTimeout(10000);
connection.connect();

InputStream stream = connection.getInputStream();

SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();

XMLReader xr = sp.getXMLReader();

xr.parse(new InputSource(stream));  // The line that throws the exception

Why would the Activity force-close and then run without any problems immediately after? Would a BufferedInputStream be any different? I’m baffled. 🙁

Thanks for your time everyone.

Update: It turns out HttpURLConnection.getResponseCode() returns -1 every so often, so the InputStream probably isn’t being correctly set.

  • 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-05-14T18:26:03+00:00Added an answer on May 14, 2026 at 6:26 pm
    HTTPURLConnection connection = (HttpURLConnection) serverAddress.openConnection();
    connection.setRequestMethod("GET");
    connection.setDoOutput(true);
    

    Those lines are a bit odd. Is it HTTPURLConnection or HttpURLConnection? The default request method is already GET. The setDoOutput(true) will however force it to POST.

    I’d replace all of those lines by

    URLConnection connection = serverAddress.openConnection();
    

    and retry. It might happen that it returned an error because you forced POST and didn’t write anything to the output (the request body). The connection.connect() is by the way already implicitly called by connection.getInputStream(), so that line is superfluous as well.

    Update: does the following for testing purposes work?

    BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
    for (String line; (line = reader.readLine()) != null;) {
        System.out.println(line);
    }
    reader.close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a weird issue that only seems to be affecting IE 7. The
I have a weird issue that only seems to show itself on IE 8
I have an weird issue, I am running the following SQL statement: SELECT *
We have a semi-weird issue for our site. Consistently, from 1 anonymous* user the
I have a weird date rounding problem that hopefully someone can solve. My client
I have a weird error in my C++ classes at the moment. I have
I have some extremely weird behavior that seems to result in silent exceptions. How
I have a really wierd issue that I'm hoping someone can shed some light
I have been facing a weird issue in a piece of code. void app_ErrDesc(char
I have a weird issue regarding buffering inputStream of pdf and odt files. They

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.