aspose file tools*
The moose likes Beginning Java and the fly likes Error Message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error Message" Watch "Error Message" New topic
Author

Error Message

S. Stacey
Greenhorn

Joined: Jul 03, 2003
Posts: 20
Hello All,
I am VERY new to Java and have come across this error message and I am not sure what it means or how to fix it.
I can complie both my class and test class and when I go to run the program I get the following error:
Exception in thread "main" java.lang.NullPointerException at Game.throwDie(Game.java:20)
at TestGame.main (TestGame.java:18)
Can some one please help me out?
Thanks
Stacey
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi Stacey
can u please post ur code if its not much big? it says that u get NullPointerException at line no:18.
NullPointerException means that - "the code tried to invoke a method on a object reference which was null". if you are famaliar with C/C++ then you can consider this NullPointerException (NPE written in short most of the time for ease) as "NULL" pointer usage.
regards
maulin
S. Stacey
Greenhorn

Joined: Jul 03, 2003
Posts: 20
Here is my code for the class:

Any help would be greatly appreciated.
Thanks
Stacey
[ July 03, 2003: Message edited by: Stacey Young ]
[ July 03, 2003: Message edited by: Stacey Young ]
[ July 03, 2003: Message edited by: Stacey Young ]
[ July 03, 2003: Message edited by: Stacey Young ]
[ July 03, 2003: Message edited by: Stacey Young ]
[ July 04, 2003: Message edited by: Stacey Young ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Stacey, if you place your code between UBB CODE tags, the formatting will be preserved and it will be a lot easier for all of us here to help you out.
hth,
bear
P.S. Welcome to the Ranch!
P.P.S. You can edit your previous post to add the code tags.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1821

Your problem is that you are "hiding" your generator in your constructor. Instead of

use

The difference? You have already declared generator as a class member; by including the type again, you are telling the compiler that you are creating a reference that is local to the constructor. When you create an object for that reference, you are not creating one for the class reference. That is never assigned a value, so it takes the default, which is null. (While the "this." is technically optional in my example above, I placed it there to help show the concept of local vs. class reference)


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
S. Stacey
Greenhorn

Joined: Jul 03, 2003
Posts: 20
WOO HOOO!!! that worked, THanks Joel!!!

and Bear I am not sure what you mean by the UBB CODE tag....can you explain it a little more to me.
Larry Cha Cha
Greenhorn

Joined: Jun 06, 2003
Posts: 15
nd Bear I am not sure what you mean by the UBB CODE tag

When replying or creating a new topic there are buttons below the Instant UBB Code label, one of which is CODE. It simply adds an open and close tags which you should place your code in to format it correctly.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Stacy, welcome to JavaRanch!
Take a look at the UBB Code explanation document for a good idea of what Bear was talking about.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
 
subject: Error Message