1

I'm new at android developement, new to Java too. Originally, I'm a C# and C++ programmer, so this is kind of suspect to me. I wrote this code

String[] teile = temp.split(" ");

int[] teileInt = new int[] 
{
    50, 50, 50, 50, 50, 50
} ;

for (int i = 0; i < teile.length; ++i) {
    try {
        Integer integer = new Integer(teile[i]);
        //int d = Integer.parseInt(teile[i]);
    }
    catch (NumberFormatException ex)
    {
        Toast.makeText(this, teile[i] + getMessagesFromException(ex), Toast.LENGTH_SHORT).show();
    }
    //

}

Both expressions turn into the same Exception!

(Cant post an image)

The Toast says:

40null Invalid int: "40"
java.lang.NumberFormatException: Invalid
int: "40"

Im sorry, but I can' t figure out whats wrong... Is 40 not an Integer?

4
  • What are you trying to accomplish with this code? Commented Mar 4, 2014 at 22:32
  • Your code does not show what the content of temp is, which constructs teile. Commented Mar 4, 2014 at 22:32
  • Post the relevant code where the exception arises. Also, post the content of temp String variable. Commented Mar 4, 2014 at 22:32
  • teileInt is never used. could you share temp's value Commented Mar 4, 2014 at 22:33

1 Answer 1

2

Try this. Integer integer = new Integer(teile[i].trim());
I assume you have a leading or a trailing space in teile[i].

Sign up to request clarification or add additional context in comments.

3 Comments

or better split by "\\s+"
@AndreiNicusan Yes, that could help too. Agreed.
youre answer was really helpfull! didnt expect it would be neceressary to trim() those!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.