I've got a Java class which contains a Color object called fillColor, along with several other colors;
Reflection is probably overkill for this, in fact I may just end up using a map, but either way this is worth asking.
Here's a method of that class which returns a color based on a string.
public Color getColor(String name) {
Field field;
Color c= new Color();
try{
field = getClass().getDeclaredField(name);
System.out.println(field.get(c));
}catch(Exception e){
System.out.println(e.getMessage());
throw new RuntimeException("wtf happened here?");
}
return c;
}
this throws an exception. It's message reads
Can not set com.badlogic.gdx.graphics.Color field com.whatever.project.Hexagon.fillColor to com.badlogic.gdx.graphics.Color
Obviously I'm confused. Is this message telling me I can't assign a Color field to a Color variable?
EDIT: stack trace
java.lang.IllegalArgumentException: Can not set com.badlogic.gdx.graphics.Color field com.whatever.project.Hexagon.fillColor to com.badlogic.gdx.graphics.Color
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164)
at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168)
at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:55)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
at java.lang.reflect.Field.get(Field.java:379)
at com.whatever.project.Hexagon.getColor(Hexagon.java:177)
at com.whatever.project.Animator$1.animate(Animator.java:45)
at com.whatever.project.Animator.animate(Animator.java:86)
at com.whatever.project.Project.render(BlackDot.java:40)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:206)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
fillColor is declared like this:
Color fillColor;
getClass()on Color instead of silentthis, also what is the actual declarationfillColor?