When I run this code I get the NullPointerException on line int length = origin.length();
If I run in the debug mode it stoped on the same line but in the variable tab the origin
value is as it might be i.e. the value from the main method.
So why is NullPointerException there in runtime?
public static void main(String[] args) {
String regexp = "(?:a)";
Task t = new Task(regexp); // error
t.process();
}
class Task {
private String origin;
public Task() {
}
public Task(String origin) {
this.origin = origin;
}
public void setOrigin(String origin) {
this.origin = origin;
}
public String getOrigin() {
return origin;
}
int length = origin.length(); //NullPointerException
...