-8

I have faced many time the NullPointerException in android. Some times I understand why the exception is thrown.

My Question is: Android applications are developed in Java and Java does not support pointers, then why is the exception called NullPointerException?

Lucifer
  • 29,392
  • 25
  • 90
  • 143
Andy
  • 15
  • 6
  • 2
    It says `NullPointerException`. A variable or an object, you declare but fotgot to initialize it. – Lucifer May 01 '14 at 11:51
  • 1
    Read http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it – Rakesh KR May 01 '14 at 11:51
  • thanks for answer, I would like to know is there any reason android call it null pointer why not 'Object or variable not initialize ? – Andy May 01 '14 at 11:58
  • I would like to worn the user who are going to negative marking of question, please understand question and if don't know answer leave it. – Andy May 01 '14 at 12:03
  • References (aka the way all objects are refered to) are very closely related to pointers – Richard Tingle May 01 '14 at 12:06
  • This isn't really a duplicate. The other question is about why its called a Null **Pointer** Exception. The other is about how to deal with it – Richard Tingle May 01 '14 at 12:09
  • Incidently, a key part of this is this: `Vector3d a=new Vector3d()`, what is `a`. If you say a `Vector3d` then that is wrong. It is **a reference** that points to a Vector3d – Richard Tingle May 01 '14 at 12:11
  • @Andy Its not called "Object not initialize" because an object may never have even existed, let along been initialized. Its not called "variable not initialized" because it might have been. For example `Vector3d a=new Vector3d(); a=null;` it was initialised (Although I'm not sure I'd call it "initialised"), then it was set to null. It could have been called a NullReferenceException – Richard Tingle May 01 '14 at 12:27
  • @RichardTingle: thanks for explaination – Andy May 01 '14 at 12:39

2 Answers2

2

NullPointerException is a situation in code where you try to access/ modify an object which has not been initialized yet. It essentially means that object reference variable is not pointing anywhere and refers to nothing or ‘null’.

  • Thanks for ans, As Java not support Pointer so why it called null pointer exception, why not something like "Object not Initialized" – Andy May 01 '14 at 12:01
  • @user138662 Java references are very similar to pointers. Java is closer to *only* pointers than no pointers (although neither are completely true). All the c deferencing rubbish is just done automatically and you can't have a reference to a reference – Richard Tingle May 01 '14 at 12:04
  • @Andy it is the reference that is null, not the object. It should be called NullReferenceException but it's not and it's too late to change it. – user253751 May 01 '14 at 19:22
0

A NullPointerException is thrown when you use a null reference. The name is a holdover from an early prototype of Java.

user253751
  • 57,427
  • 7
  • 48
  • 90