Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java help with world of zuul game

807569May 16 2006 — edited May 17 2006
so I have this code, but i keep getting a null pointer exception. after using a debugger, ive found that "theItems" is a "null" variable. im slightly confused by this. Is it because its considered a String and the method calls for an Item? ANd if so, how do you fix it? please help.



"""""""""""""""""""""""""METHOD TAKE"""""""""""""""""""'
private void take(Command command)
    {
      String theItem = command.getSecondWord();
        Item theItems = currentRoom.getItem(theItem);
        
            if (!command.hasSecondWord()){
                gui.println("Take what?");
            return;
            }
            if(currentPlayer.getMyCarriedWeight() +
                theItems.getWeight() > currentPlayer.getMaxWeight()){
                gui.println("This Item is too heavy for you to carry!");
            return;
            }
            if(theItems.isMoveable()){ 
                gui.println("You can't move the item");
            return;
            }
            
            currentPlayer.addItem(theItems);
            gui.println("The item has been taken");
            currentRoom.removeItem(theItems);
    }
""""""""""""""""""""""""""ITEM CLASS """""""""""""""""""""""""""""""


public class Item
{
    private String description;
    private String name;
    private int weight;
    private boolean moveable;


    public Item(String myDescription, String myName, int myWeight, boolean itemMoveable)
    {
        this.description = myDescription;
        this.name = myName;
        this.weight = myWeight;
        this.moveable = itemMoveable;       
    }


    public String getDescription()
    {
        return description;
    }
    

    public String getName()
    {
        return name;
    }
    
    
    public boolean isMoveable()
    {
        return (moveable == false);
    }
    

    public int getWeight()
    {
        return weight;
    }
    
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 14 2006
Added on May 16 2006
11 comments
1,219 views