+ 2
How can I solve this Empty String Exception?
Hello, could someone help me find the problem? I know StringTokenizer isn't recommended but it's required by a school assignment. It says Exception in thread "main" java.lang.NumberFormatException: empty String https://code.sololearn.com/cVKVF4HzURl7/?ref=app
1 Réponse
+ 4
1. I have commented out the line causing error to clear the mist
https://code.sololearn.com/capZX1UyrQ6X/?ref=app
Instead of 50, then 30, then 90,
t actually is "", 50, 50, 5030, 5030 and then 503090.
That's because you haven't reset t back to "" at start of each outer loop.
2. After adding t = "" before inner loop,
https://code.sololearn.com/cLnxKg502gyo/?ref=app
You should be able to see that actually you output three empty lines. So instead of 3 iterations, you have 6 iterations.
3. Now we print tokens to examine what happens :
https://code.sololearn.com/cEf3WvkMH2QS/?ref=app
You see? You get 6 tokens. So when the token doesn't contain number, t is empty string that round, and that's the round that cause the error.
4. For this problem, you can add a if-else to contain the m+= line.
5. Overall, this demonstrate how you can debug a program step by step.
Don't be afraid of bugs. Debug bugs. Don't give up.