This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes errrrr Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "errrrr" Watch "errrrr" New topic
Author

errrrr

Dishi Malhotra
Greenhorn

Joined: Dec 13, 2000
Posts: 22
This code is giving me error : I don't know what is it
(This code is written for how much time the rediff.com is open)

I added code tags for you.
[This message has been edited by Randall Twede (edited March 05, 2001).]
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

You can learn about UBB tags here http://www.javaranch.com/ubb/ubbcode.html
If you cant get an answer here. I will move it to the sockets forum tomorrow.


SCJP
Visit my download page
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Originally posted by Dishi Malhotra:
t1 = new Thread();
t1 = null;
t1.start();


So you create a new thread. They you take way the only reference to it by setting the variable referencing it to mull. Then you start it???
Perhaps I am missing something, but looks to me like t1 is food for the gc().


"JavaRanch, where the deer and the Certified play" - David O'Meara
Dishi Malhotra
Greenhorn

Joined: Dec 13, 2000
Posts: 22
Candy i can't get u what u want to say so plz explain
Siva Prasad
Ranch Hand

Joined: Feb 22, 2001
Posts: 104
Hi Dishi
What Cindy was trying to say ...
when you say
t1 = new Thread();
a new Thread Object is created referenced by t1.
immediately you are setting this t1 to null which means there is no object associated with t1 now when you say this t1 = null;
After that you are trying to call a method start() [t1.start()] for this reference which doesnot have any association with any object. So as a result you get a NullPointerException when u try to access this function.
During the course of time, since the Thread object created has no reference, this will be destroyed by GarbageCollector.
Hope this clears your doubt
cheers
Siva Prasad
[This message has been edited by Siva Prasad (edited March 07, 2001).]
 
 
subject: errrrr