• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

help with java. lang. NullPointer Exception

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

CScon

CTimer

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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Amit Ellana
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Ernest Friedman-Hill but im not sure what the answer is? could you explain it a bit more or point me to a place where I could find that answer....again thanks for the help
amit
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Amit Ellana
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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'?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Amit Ellana
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.....
 
reply
    Bookmark Topic Watch Topic
  • New Topic