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 Programmer Certification (SCJP/OCPJP) and the fly likes  NullPointerException 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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark " NullPointerException" Watch " NullPointerException" New topic
Author

NullPointerException

chintan ramavat
Ranch Hand

Joined: Sep 15, 2006
Posts: 134
Hello Ranchers

Quick question

woud that exception works only for ARRAY or if we assign array reference value to some undefined type and then we try to access it. would it also give the same exception in accessing undefined variable.

example class A {

int a;
}
class B {

int [] b = new int(1);

A me = new A();
me.a;
} //pardon for detail syntax liike main and all

- just wanna make sure cases when we get NullpointerException
- Thank you ranchers
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Why dont you run it ? Primitive instance variables like int are defaulted to 0


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
chintan ramavat
Ranch Hand

Joined: Sep 15, 2006
Posts: 134
hi john ,

i know the defaults assignments for primmitives but wanted to know that what if we access the primmitive which is declared and we are assigning NULL array value in it.

thank
Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 355

NullPointerException is thrown when the reference can't find an object to refer, when you are assuming that it actually refers an object!
By the way, an int[] can hold only integers; not objects!
Read it as "an integer array" where [] stands for array and int stands for integer. Precisely, it is an array that holds integers - got it?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException