Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

y am i getting null pointer exception here?

 
krishna balaji
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the code and i am null pointer exception


[ EFH: Fix code tags ]
Wat can b various reasons for getting null pointer exceptions
[ October 30, 2006: Message edited by: Ernest Friedman-Hill ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NullPointerException always means that you've tried to access an object that simply isn't there; i.e., a variable's value is null instead of referring to an object. In general, it's a variable followed by a dot (or an open square bracket, if it's an array.)

This is far too much code for me to look at, but if you look at your stack trace it will tell you what line number the exception occurs on. If you then indicate to us exactly which line of code that is, I'm sure we can help you out.
 
sven studde
Ranch Hand
Posts: 148
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You also need to use code tags. If you look at your code after you post, and your code is a mess, then you need to do something about it if you want people to answer your question.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sven studde:
You also need to use code tags.


To be fair: he did, they were just broken. I fixed them.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you use an IDE? If so, just check at which line the NullPointerException occurs.
 
krishna balaji
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[code]
confserver obj[];
//i am getting null pointer error in the following line wats the problem
obj[i].m=new messageQ();
obj[i].g.start();
obj[i].s.start();
[code]

confserver is class in defined how to create array of the class ?
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

if the code compiles, the confserver object array must be non local.
Most probably the array is empty. If it is non local (i.e. an instance variable) it even may be not initialized.
In both cases (empty or uninitialized) a null pointer exception is thrown.


Simple example


Prints null
and then throws NullPointerException.


By the way, Krishna, you should give classes identifiers that start with an uppercase letter. Makes the code easier to read (for humans, not for compilers).

krishna balaji wrote
confserver is class in defined how to create array of the class ?
confserver obj[];
It is declared but not defined and filled yet, not even an empty array, but a reference to a confserver array.
Please put the brackets behind the class identifier
confserver[] obj;
would be the normal way to say this. The way you did it works, but is unusual and also harder to read.
obj is not a nice name for a variable. It tells you nothing.

Declare, initialize and fill an array, example:




Yours,
Bu.
 
krishna balaji
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you sir that was very informative now i understand the problmem
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic