A
A
Alexander Odintsov2015-11-20 00:35:26
Java
Alexander Odintsov, 2015-11-20 00:35:26

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);		
  }

What could be the problem? Thanks in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
poiuy7, 2015-11-20
@ShumaHerr

I think the problem here is s.toLowerCase()
if s==null -> then s.toLowerCase() will be NullPointExeption

P
Praytic, 2015-11-20
@Praytic

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.

O
one pavel, 2015-11-20
@onepavel

You have NullPointExeption because you are accessing an uninitialized reference.
It can be either stringSet or s
Great 3 Simple Methods

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question