Answer the question
In order to leave comments, you need to log in
Why does NullPointExeption crash?
Good afternoon. I have a problem with a learning task. The essence of the task is to work with multiple lines. I am using Hashset. I wrote the implementation of almost all methods, but when checking on the educational portal, not a single method passes the test, all of them give a NullPointExeption error. For example, here are 3 simple methods from this class:
@Override
public void add(String s) {
this.stringSet.add(s.toLowerCase());
}
@Override
public boolean remove(String s) {
return stringSet.remove(s.toLowerCase());
}
@Override
public void removeAll() {
stringSet.removeAll(this.stringSet);
}
Answer the question
In order to leave comments, you need to log in
I think the problem here is s.toLowerCase()
if s==null -> then s.toLowerCase() will be NullPointExeption
Did you run the program yourself? I would run it in debug mode and find my zero pointer. By the methods that you threw off, you can guess that you are trying to remove a non-existent element.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question