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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:44:11+00:00 2026-06-06T11:44:11+00:00

I am getting this LogCat: 06-22 15:30:53.731: E/AndroidRuntime(2389): java.lang.NumberFormatException: Invalid float: null 06-22 15:30:53.731:

  • 0

I am getting this LogCat:

06-22 15:30:53.731: E/AndroidRuntime(2389): java.lang.NumberFormatException: Invalid float: "null"
06-22 15:30:53.731: E/AndroidRuntime(2389):     at java.lang.StringToReal.invalidReal(StringToReal.java:63)
06-22 15:30:53.731: E/AndroidRuntime(2389):     at java.lang.StringToReal.parseFloat(StringToReal.java:310)
06-22 15:30:53.731: E/AndroidRuntime(2389):     at java.lang.Float.parseFloat(Float.java:300)
06-22 15:30:53.731: E/AndroidRuntime(2389):     at java.lang.Float.valueOf(Float.java:337)

Here is code:

try
{
    jObject = new JSONObject(result);
    starAvg = jObject.getString("AverageRating"); 
}
ratingsBar = (RatingBar) findViewById(R.id.theRatingBar);
ratingsBar.setRating(Float.valueOf(starAvg));

Here is the context:

In PHP, I am averaging total numbers in a column in a MySQL table. When there are ANY rows, it will send back an average of the data in it and it encodes it, and Java picks it up as a JSON object. But sometimes, there are cases where a table may have 0 rows, so I get this JSON Object:

 {"AverageRating":null}

My app then crashes and the LogCat is as seen above.

The String doesn’t seem to care if it picks up a Null JSON Object but the app crashes when I do Float.valueOf(theString).

Another side note, I have tried to test this way:

if String is Null, Float = 0 
if String is not null, Float.valueOF(String)

But it doesn’t ever seem to read the String as null. Is it actually NOT null in this case?

  • 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-06T11:44:14+00:00Added an answer on June 6, 2026 at 11:44 am

    Use the following method of JsonObject to check if a value against any key is null

    public boolean isNull(java.lang.String key)
    

    This method is used to check Null against any key or if there is no value for the key.

    Use below snippet

    if (jsonObject.isNull("AverageRating")) {
        Toast.makeText(this, "Cannot Convert!!", Toast.LENGTH_LONG).show();
        //float set to 0
    } else {
        Float.valueOf(jsonObject.getString("AverageRating"));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im getting an error from logcat: 01-13 17:53:25.368: E/AndroidRuntime(3235): Caused by: java.lang.NullPointerException 01-13 17:53:25.368:
I am getting this in LogCat: 05-20 17:16:34.721: E/AndroidRuntime(30461): FATAL EXCEPTION: main 05-20 17:16:34.721:
getting this error in logcat 09-15 14:38:09.944: ERROR/AndroidRuntime(1065): FATAL EXCEPTION: AsyncTask #1 09-15 14:38:09.944:
I am getting this exception in the LogCat: Unable to start service Intent {
I keep getting this : DeprecationWarning: integer argument expected, got float How do I
I can't figure out why I'm getting this error in logcat: 02-14 15:44:42.470: E/ActivityThread(32164):
I am getting a NullPointerException becauase of this LogCat message: 02-17 13:01:10.766: W/System.err(950): org.json.JSONException:
I am getting the IllegalAccessError while running Android instrumentation tests. This is Logcat output:
I am getting this error from the logcat org.apache.http.NoHttpResponseException: The target server failed to
I am getting this exception in database Leak Found my LOGCAT Shows this: 02-17

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.