I apologize in advance if this has been asked elsewhere, but I have looked around and I can't seem to find an answer that fits my situation.
Some background: I have taken it upon myself to write a sort of "RPG character builder" for the Savage Worlds RPG system. I am using the NetBeans IDE to design a UI for this application. So far, things have gone pretty smoothly, but I am now encountering an error I can't seem to figure out.
I have a set of Attributes: Agility, Strength, Smarts, Spirit, and Vigor. The values for those attributes are a Die-type, ie d4, d6...d12. I created an Enum to represent these die types:
public enum DieType {
D4(4), D6(6), D8(8), D10(10), D12(12);
private int face;
private DieType(int face) {
this.face = face;
}
public int getValue() {
return face;
}
@Override
public String toString() {
String dieType = "d" + face;
return dieType;
}
}
In my UI, I created a series of JSpinners to be able to adjust the values for each attribute. I wanted to use those die types in the spinners, so I initialized a new SpinnerListModel for them:
agiSpin.setModel(new SpinnerListModel(DieType.values()));
So far, so good, everything is still working well, and I can run the application and the window appears with the Enum list populated for each of the spinners. (Planning to move the model initialization to a variable that I can plug into each individual spinner, but right now I am working with NetBeans-generated code, so am creating each instance separately).
The problem occurs when I attempt to intialize a value for each spinner based on an instance of my SWCharacter
class, instantiated before the GUI is drawn. For the above agiSpin
spinner, I do as such: agiSpin.setValue(swchar.getAgiAttr());
in order to assign the appropriate value. The variable agiAttr
is an instance of the DieType
Enum. When I run the program, I get:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: invalid sequence element
at javax.swing.SpinnerListModel.setValue(SpinnerListModel.java:185)
at javax.swing.JSpinner.setValue(JSpinner.java:356)
...originating from that attempt to set the value.
What am I doing wrong with this? Do I need to create the List Model in a different way? Is there a syntax error in the way I'm attempting to assign values?