NullPointerException.CLARIFICATION
there are no pointers in java,
but pointer means variable, is it right?
so when i encounter these kind of error(NullPointerExcpeion) it means that .. the variable that im reffering to, does not contain anything.(Null or no value) ,do i make any sense about this matter?
am i right?
Re: NullPointerException.CLARIFICATION
The way Java's object variables work is by using pointers of sorts. The only thing is you can't modify the value directly, you have to reference it to some existing object or create a new one and reference to it.
Null Pointer Exception just means that your variable is not pointing to an object. Since you can't manage memory primitively with pure Java, you can't delete an object when something is still referencing it, so it's impossible to have an "empty" object.
Re: NullPointerException.CLARIFICATION
ahm helloworld
can you give some code examples of that, im a bit confused... please......
tnx tnx tnx.....
Re: NullPointerException.CLARIFICATION
You were right in your first post, when a variable is assigned with null it is actually pointing to null/nothing which means that if you try to invoke a method on that null reference will give you a NullPointerException.
Taken from NullPointerException (Java Platform SE 6)
Quote:
Thrown when an application attempts to use null in a case where an object is required. These include:
Calling the instance method of a null object.
Accessing or modifying the field of a null object.
Taking the length of null as if it were an array.
Accessing or modifying the slots of null as if it were an array.
Throwing null as if it were a Throwable value.
// Json
Re: NullPointerException.CLARIFICATION
tnx json i tried to output an error like that with two different simple program
here it is
first code
Code :
String word = null;
System.out.print(word);
it only prints the word null
BUT-
second code
Code :
String word = null;
StringBuilder builder = new StringBuilder(word);
System.out.println(builder);
i've noticed the difference between the two
can i consider the second code as "Referencing"
then if it is..
im cleared out
tnx Json for that information
Re: NullPointerException.CLARIFICATION
Try this one.
Code :
String word = null;
String upperCaseWord = word.toUpperCase();
// Json
Re: NullPointerException.CLARIFICATION
same output sir
is that what they call "Referencing" ?
Re: NullPointerException.CLARIFICATION
Id say its because of this.
Quote:
Accessing or modifying the field of a null object.
// Json
Re: NullPointerException.CLARIFICATION
Quote:
String word = null;
System.out.print(word);
The reason it prints out "null" is somewhere inside the print method there's a line that looks like this:
Code :
if (txt == null)
{
//printout "null"
}
I believe the print method does a similar thing when you try 1/0 (except it'll print out infinity, or NA)