Hy!
I want to parse a String to a Integer. The String is like the format for series: SXXEXXX
The Code should increase the episode.
Like: S01E01 --> S01E02 Also: S01E100 --> S01E101
Code:
String s = episodes.get(episodes.size()-1);
Log.e("DBManager",s);
if (s.split("E").length <= 2) {
int i = Integer.getInteger(s.split("E")[1].split(" ")[0]); //NullPointerEx
return s.split("E")[0]+"E"+String.valueOf(i++);
}
Log:
10-26 15:56:34.635: E/DBManager(932): S00E01
Integer.getInteger() is not the correct method to use.
You should be using Integer.valueOf()
Integer.getInteger(String s) will return the integer system property with the key s.
The null pointer occurs because this method can't find the property with the key you supply and returns null. Java then tries to unbox this to an int and null pointers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With