I have following problem;
I have inerface with public method clone():
public interface Something {
Something clone();
}
and also
public class SomethingImpl implements Something {
private Something some;
public Something clone() {
return some.clone();
}
}
Whenewer I run from code somewhere
...
Something i = new SomethingImpl();
...
// do something on i
...
someMethod(i);
...
public void someMethod(Something some){
Something some2 = some.clone();
}
I get Exception in thread “main” java.lang.NullPointerException on line Someting some2 = some.clone;
I programmed a lot bussiness logic, but never till now I encountered neccessity of cloning, esspecially this way.
Can someone point me in which direction I should go? I tried to read articles on this topic but just got more confused.
Thanks in advance,
Mile
A method and a field are two different things.
cloneis a field, which is not defined and hence will not exist.clone()is a method. Did you meanSometing some2 = some.clone()?Edit I just saw your actual error (although what I said above should still be heeded!). This means that
somemust benull– are you perhaps changing its value in the portions of code you omitted? Be sure to check for that whenever you receive aNullPointerException.