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;
}
}