• 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
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

y am i getting null pointer exception here?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
author and iconoclast
Posts: 24208
47
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
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.
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24208
47
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

Originally posted by sven studde:
You also need to use code tags.



To be fair: he did, they were just broken. I fixed them.
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you sir that was very informative now i understand the problmem
reply
    Bookmark Topic Watch Topic
  • New Topic