Search code examples
javaandroidintegernumberformatexception

I have a number format exeception error


I received this error "java.lang.NumberFormatException: Invalid int: "3e+06"" and its preventing my application to run. I am passing an numeric string value to an int and this occurred. Would it be that the numeric is to big for an integer? Could anyone tell me what this means and any solutions for it?

        Bundle getAlarmInfo = getIntent().getExtras();
        titleOfAlarm = getAlarmInfo.getString("Title");
        totalTime = getAlarmInfo.getString("totalTime");

// Ok so I am trying to get the value of getAlarmInfo.getString("totalTime"); and pass it to total time which is a string

        actualTimeFiniliazedInMilliSeconds = Integer.parseInt(totalTime);

//then I am taking that value and storing it in actualTimeFiniliazedInMilliSeconds which is a int.

  titleTextView.setText(titleOfAlarm);

// I then pass that value to CountDownTime which only accepts ints and longs.

        countDown = new CountDownTime( actualTimeFiniliazedInMilliSeconds, timeInterval);
        countDown.start();

Solution

  • First of all you should post some code, but:

    1. what value are you parsing ?

    2. the fastest way to check if value is too big is parsing it to Long type. If it fits you have your answer

    // edit

    If you need int or long and you're casting string that is 3e+06 try casting it to BigInt and from it to Integer. Integer can handle value of 3000000 it is not a problem. But it has problem with casting from string so using my way should be ok