Why does setting Java object subscr1=null don't initialize new subscr1?
Ugur58May 25 2011 — edited May 31 2011HI all,
I have code a program that passes a certain number from 5000 till 50000 to a subscribe method in a for loop. There is an object subscription1 of class type Subscription which I initialize and use in my subscribe method in each loop. When I set my object at the end of each loop to null (subscription1=null) and initializing and use it in the next loop , I get a NullPointerException NPE.
Why doesn't it run when I am calling this subscribe method from another class?
class A{
public subscribe(int i){
Subscription subscription1 = new Subscription();
DoSomething();
...
subscription1=null;
}
}
class B{
for (int i=5000; i<50000;i+=5000){
subscribe(i);
}
}
Thank you all in advance
BR, Ugur
Edited by: user12246908 on May 25, 2011 2:00 AM