• 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

NullPointerException

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why dont you run it ? Primitive instance variables like int are defaulted to 0
 
chintan ramavat
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 358
Firefox Browser Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic