-3

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.substring(int, int) Fatal Exception main

1 Answers1

0

This exception is thrown when you are trying to use the substring method on a null string, try checking the value of the string you are invoking the substring method. If you want to avoid the crash you can use the following code

if(str!=null){
   //where the str is the string you are invoking the method on
   substr = str.substring(7, 17);
}
Sami Kanafani
  • 8,640
  • 4
  • 35
  • 33
  • Since this is more often than not a programming error, the crash is preferable over some strange misbehaviour due to substr not being set. (Fail fast). – Henry Jun 28 '17 at 18:15