The Artima Developer Community
Sponsored Link

Java Answers Forum
I am getting a nullpointer exception

1 reply on 1 page. Most recent reply: Aug 14, 2003 1:03 PM by Henk de Vries

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Draganka Tusheva

Posts: 8
Nickname: tusheva
Registered: Aug, 2003

I am getting a nullpointer exception Posted: Aug 14, 2003 8:28 AM
Reply to this message Reply
Advertisement
Hi so I am new to this forum and still a student in computer science ...
So my question is what exactly is a nullpointer exception and when did i get one
I wanted to create a hash table where i could put some stuff but unfortunately when i execute my code i ma getting this error.
I appreciate any help
Gery


Henk de Vries

Posts: 1
Nickname: henkie71
Registered: Aug, 2003

Re: I am getting a nullpointer exception Posted: Aug 14, 2003 1:03 PM
Reply to this message Reply
Hi!

Java works with references. When you create a variable,
normally you create a reference to an object, such as an
Integer. So you could say the variable points to the object. You might have done something like this:

HashMap h;
h.put("name", "henk");

or

HashMap h = null;
h.put("name", "henk");

Every object that is declared in java refers to null, you
could say points to nothing. So when you execute above code you use a reference to null trying to access the objects'
put method. This causes the java interpreter to throw a NullPointerException. Now for the solution:
Declaring means only: saying to the computer that your variable exists, not what it is.
The fix for the above solution is not only declaring but also initializing your variable:

HashMap h = new HashMap();
h.put("name", "Henk");

If this does not help, send the code snippet that causes the Exception.
regards

Henk

> Hi so I am new to this forum and still a student in
> computer science ...
> So my question is what exactly is a nullpointer exception
> and when did i get one
> I wanted to create a hash table where i could put some
> stuff but unfortunately when i execute my code i ma
> getting this error.
> I appreciate any help
> Gery

Flat View: This topic has 1 reply on 1 page
Topic: problems compiling with dependencies Previous Topic   Next Topic Topic: ClassLoader help

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use