Samasaur1 / CityManagement

A text-based city management game
3 stars 7 forks source link

Construct City NPE #45

Open ksadman opened 3 years ago

ksadman commented 3 years ago

Describe the bug:

Attempting to construct city results in NullPointerException

To Reproduce:

Steps to reproduce the behavior:

  1. Start new game
  2. Enter the following command: construct city

Expected behavior:

I expect the game to not crash. I don't know what a city is intended to do yet, so I can't speak to any further expected behavior

Desktop (please complete the following information):

Stack trace:

Exception in thread "main" java.lang.NullPointerException at com.samgauck.CityManagement.Economy.getPrice(Economy.java:95) at com.samgauck.CityManagement.Economy.updatePrice(Economy.java:129) at com.samgauck.CityManagement.Command.construct(Command.java:277) at com.samgauck.CityManagement.Command.execute(Command.java:69) at com.samgauck.CityManagement.Main.main(Main.java:143)

Additional context:

At a glance, it seems like it is trying to update the price of city after constructing it. But "city" is not in the list of items, so it fails. One possible solution is to simply not try to update the price if the constructable is not in items. In fact, I think that is what was intended by this: if (!item.contains(item)) return; I think that line was meant to be this if (!items.contains(item)) return;