aspose file tools*
The moose likes Beginning Java and the fly likes i get null expression when trying to call from another class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "i get null expression when trying to call from another class" Watch "i get null expression when trying to call from another class" New topic
Author

i get null expression when trying to call from another class

Sid James
Greenhorn

Joined: Sep 16, 2009
Posts: 7
m
James Ward
Ranch Hand

Joined: Apr 27, 2003
Posts: 263
Change this line inside the constructor of Dice class (the class level variable mRandom will remain null otherwise):



to this:


Sid James
Greenhorn

Joined: Sep 16, 2009
Posts: 7
Hello,

It still says NullPointerException when i call AttackValue (after i changed the Random mRandom to just mRandom)
Please let me know if you can see something else that could be the problem.

D. Ogranos
Ranch Hand

Joined: Feb 02, 2009
Posts: 214
Same mistake with Dice in the constructor of class Hero...you declare a local variable of type Dice there, but probably want to assign it to your instance variable.
Himanshu Kansal
Ranch Hand

Joined: Jul 05, 2009
Posts: 257
One problem I see is about the missing code tags.

Next, you instead of refereing to instance variables in the constructors, create new automatic ones.


Experience and talent are independent of age
Sid James
Greenhorn

Joined: Sep 16, 2009
Posts: 7
D Ogranos - do you mean mSides?

like Dice mDice = new Dice(mSides)? (in the constructor of Hero)

or should i change the type of Dice?
Sid James
Greenhorn

Joined: Sep 16, 2009
Posts: 7
Himanshu - like this?

(constructor)
Dice mDice = new Dice()

Im sorry that may be the way i already written. How do you mean?
James Ward
Ranch Hand

Joined: Apr 27, 2003
Posts: 263
In the constructor of Hero class.

Change this line:

to this:


Sid James
Greenhorn

Joined: Sep 16, 2009
Posts: 7
I think ive fixed it!!! Thank you so much. I made the method create a new Dice. Allthough now it is returning the same numbers, but that isnt a big problem. Thank you!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: i get null expression when trying to call from another class