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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:23:31+00:00 2026-05-28T01:23:31+00:00

When i download data on the web, sometimes it works and sometime it doesn’t.

  • 0

When i download data on the web, sometimes it works and sometime it doesn’t.
And my problem is in one int :
runtime: “”

runtime is an int and when i use gson on it can cause this problem :

01-07 21:22:57.602: E/AndroidRuntime(2726): Caused by: java.lang.NumberFormatException: Invalid int: ""

and i tried to some if statement but it doesn’t work.

public int getRuntime() {
    if(Integer.valueOf(runtime)==null){
        return 0;
    }else{
        return runtime;
    }
}

or even

public int getRuntime() {
    if(Integer.valueOf(runtime).equals(null)){
        return 0;
    }else{
        return runtime;
    }
}

but nothing works.

  • 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-28T01:23:32+00:00Added an answer on May 28, 2026 at 1:23 am

    Integer.valueOf() expects a String representing an integer. Calling it with an empty string will lead to an exception. You need to test the String before parsing it as an integer:

    int runtime;
    if ("".equals(string)) {
        runtime = 0;
    }
    else {
        runtime = Integer.parseInt(string);
    }
    

    or, if you always want that runtime is 0 if the string is not a valid integer, then catch the exception:

    try {
        runtime = Integer.parseInt(string);
    }
    catch (NumberFormatException e) {
        runtime = 0;
    }
    

    Now, it it’s gson that parses the string for you, and this string is not always an integer, then the runtime field should not be an int, but a String. And you should parse it yourself, as shown above.

    Given your question, before trying to do anything with gson and android, you should learn the basics of the Java language. You don’t seem to understand the type system in Java and what exceptions are. Read http://docs.oracle.com/javase/tutorial/java/nutsandbolts/

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

Sidebar

Related Questions

I have one activity which download data from the web. In middle of the
I want my web application users to download some data as an Excel file.
I have a web site which I download 2-3 MB of raw data from
Im trying to download share data from a stock exchange using python. The problem
Where I can download sample database which can be used for data warehouse creation?
i am making an iphone app that get data from web ,i use HPPLE
Alternative titles How to download a web page data in Objective-C on iPhone? How
All, I am trying to download the weather data history from Wunderground. The problem
I'm working on a web application. There is one place where the user can
I have a doubt regarding downloading data from a web service. One way is

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.