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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:06:30+00:00 2026-05-27T09:06:30+00:00

I’m a relative newbee to Android/Java and about to despair over a problem I

  • 0

I’m a relative newbee to Android/Java and about to despair over a problem I can’t seem to fix: I’m trying to read a few datapoints from an XML API website. Since I need to read it for five different API calls in a row and there is a lot of data on the website (about 1.3kB each), I thought it best to read the whole thing as text and simply parse it for the data I need. I’m using this code:

      char[] buffer = new char[16384];

      for (cnt=0; cnt<numcities; cnt++)
        {
            try 
              {
              url = new URL(urlStrings[cnt]);
              urlConnection = (HttpURLConnection) url.openConnection();

              try 
                {
                inStream = new BufferedInputStream(urlConnection.getInputStream());

                if (inStream != null)
                  {
                  try 
                     {
                    reader = new BufferedReader(new InputStreamReader(inStream, "UTF-8"));

                     while ((charcount = reader.read(buffer)) != -1) 
                       {
                       writer.write(buffer, 0, charcount);
                       }
                     } 
                   finally 
                     {
                     inStream.close();
                    inputLine = writer.toString();
                    }
                  }
                } 
              finally 
                {
                urlConnection.disconnect();
                }
              }
        catch (MalformedURLException e) 
          {
          }
        catch (IOException e) 
          {
          e.printStackTrace(); 
          }

      if (inputLine != null)
        {
// process the text and extract the data; the data points from five API calls all end up in one string eventually
   }
} // end for loop

This code worked fine until last week; suddenly (without me having changed anything), the app crashes, on the emulator and on my phone (the same app that worked last week!) with an exception thrown, as follows:

threadid=7: thread exiting with uncaught exception (group=0x4001d800)
FATAL EXCEPTION: AsyncTask #1
java.lang.RuntimeException: An error occured while executing doInBackground()
at android.os.AsyncTask$3.done(AsyncTask.java:200)
at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
at java.lang.Thread.run(Thread.java:1096)
Caused by: java.lang.NumberFormatException: 
at org.apache.harmony.luni.util.FloatingPointParser.parseFltImpl(Native Method)
at org.apache.harmony.luni.util.FloatingPointParser.parseFloat(FloatingPointParser.java:321)
at java.lang.Float.parseFloat(Float.java:291)
at java.lang.Float.valueOf(Float.java:330)
at com.gbg.android.china.ShowInfoQuif$DownloadROETask.doInBackground(ShowInfoQuif.java:270)
at com.gbg.android.china.ShowInfoQuif$DownloadROETask.doInBackground(ShowInfoQuif.java:1)
at android.os.AsyncTask$2.call(AsyncTask.java:185)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
... 4 more

What I’m trying to read is Google’s weather API, by the way. It looks like this:

<?xml version="1.0"?><xml_api_reply version="1">
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" >
  ...
</weather>
</xml_api_reply>

Adding some debugging code indicates the exception is triggered by this line:

                    inStream = new BufferedInputStream(urlConnection.getInputStream());

Strangely, the exception does not always happen at the same point. Usually, it happens on cnt=1, when the second URL is called. However, the app sometimes crashes at the first, third, or last one. Another funny thing is the debugging info indicates all five URLs are correctly read and the expected result returned, even though Android then exits the app. What could be wrong here?

I know the fixed buffer size I’m using is not ideal but suspect that’s not the issue here. Anybody have a suggestion how to make this work or at least how to catch the exception? I would surely appreciate it!

  • 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-27T09:06:31+00:00Added an answer on May 27, 2026 at 9:06 am

    The problem does not appear to have anything to do with your URL-downloading code. The stack trace is leading you to a call to Float#valueOf(String) on line 270 of ShowInfoQuif.java:

    Caused by: java.lang.NumberFormatException: 
    at org.apache.harmony.luni.util.FloatingPointParser.parseFltImpl(Native Method)
    at org.apache.harmony.luni.util.FloatingPointParser.parseFloat(FloatingPointParser.java:321)
    at java.lang.Float.parseFloat(Float.java:291)
    at java.lang.Float.valueOf(Float.java:330)
    at com.gbg.android.china.ShowInfoQuif$DownloadROETask.doInBackground(ShowInfoQuif.java:270)
    

    The String argument that is being passed to Float#valueOf(String) is not in a recognized floating point number format.

    See if you can trace where the invalid String value is coming from. It might help to log the string using Log#d(String, String) before calling Float#valueOf(String).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have thousands of HTML files to process using Groovy/Java and I need 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.