please help i have been getting this error and i cant fix it a lil background info: This is my first major java project after HelloWorld, its suppose to be a Client Server program. I got the Client Server part to work with both echoing a string back and forth...Then i wanted to add something that would let the server know when a client is no longer available....so i add timers to both the server and the client...for the client timer i wanted it to send a "*" to server every 10 seconds.but when the client timer tries to send the "*" java.lang.NullPointerException.....please take a look at my code and tell me what i am doing wrong im posting only the client codes cuz i feel that is what is causeing the problem CThreaded a threaded client, CScon connection class for the client, and CTimer a client timer. //CThreaded
the error message is: java.lang.NullPointerException at nwpj.CTimer.run(CTimer.java:97)
if you could please tell me what is causing this error or if you could atleaset explain the error to me i would be greatful.. Amit
No value is ever assigned to the member variable "silfa" in CTimer, so in CTimer.run, when you call a method on silfa, you get a null pointer exception. silfa has to get initialized to point to a CScon object; you should probably do this in a constructor for CTimer, which would takethe CScon as a constructor argument.
You would definitely benefit from reading some of the JavaRanch "campfire stories", here and especially here. If you read and understand both of these, then the answer to this problem should be obvious. I'm going to move this thread to "Java in General (Beginner)" because the problem has nothing to do with Sockets, per se. Followups there, please. [ November 08, 2003: Message edited by: Ernest Friedman-Hill ]
Joined: Mar 22, 2003
I have read the two articles above, but still can't resolve my problem. I need to create a constutor in CTimer but im still not sure what value to put into 'silfa'?
author and iconoclast
CTimers are being created by code inside a method of CScon, so it's clear that a CTimer should have a reference to the particular CScon object that created it, right? So the CScon code should pass "this" to the CTimer constructor, which should store that argument into the member variable. Inside any member method, the keyword "this" refers to the object on which the method was invoked.
Joined: Mar 22, 2003
thanks for the help....i think im a bit in over my head with this issue and i need to take a couple steps back and review.....
subject: help with java. lang. NullPointer Exception