Note that there are some explanatory texts on larger screens.

plurals
  1. POMap NullPointerException in Play Framework
    primarykey
    data
    text
    <p>I have a class for Vehicle and what I'm trying to do is link a bunch of VehicleParts to this Vehicle. Obviously, a normal vehicle can't have two engines, so what I'm thinking of storing them in is a map, more specifically an EnumMap</p> <pre><code>public enum VehiclePartType { ENGINE_BLOCK, CRANKSHAFT, //..etc } public class VehiclePart { public String name; public VehiclePartType partType; //some more basic variables + ModelFinder } public class Vehicle { //some basic string variables and a ModelFinder @ManyToMany public Map&lt;VehiclePartType, VehiclePart&gt; parts = new EnumMap&lt;VehiclePartType, VehiclePart&gt;(VehiclePartType.class); } </code></pre> <p>Usage: When i try to associate a part with a given vehicle.</p> <pre><code>Vehicle vehicle = Vehicle.finderVehicle.byId(id); VehiclePart vehiclePart = VehiclePart.finderVehiclePart.byId(partId); vehicle.parts.put(VehiclePartType.ENGINE_BLOCK, vehiclePart); vehicle.saveManyToManyAssociations("parts"); </code></pre> <p>This creates the table I want in the SQL database and stores the proper reference IDs, but whenever I try to access it via Java code, such as the following code, I get an error:</p> <pre><code>Vehicle.allVehicles(); [RuntimeException: java.lang.IllegalArgumentException: (was java.lang.NullPointerException) (through reference chain: com.avaje.ebean.common.BeanList[1]-&gt;models.Vehicle["parts"])] </code></pre> <p>If I change the map to a list, this works fine, but that's not what I'm going for since I won't be able to get a part by its VehiclePartType without searching through the entire list of parts.</p> <p>First, is this an acceptable way of storing the VehicleParts?<br> Second, I'm not sure how to resolve this null error. Any help with this would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload