Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Why does setting Java object subscr1=null don't initialize new subscr1?

Ugur58May 25 2011 — edited May 31 2011
HI 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 28 2011
Added on May 25 2011
18 comments
260 views