I'm trying to create my first game in Java, but I keep getting an IllegalAccesError. Both files are saved insinde the same folder. Everything is set to public and the error only occurs at runtime, so tha would mean that the class should've incompatibly changed, but I can't find it. Can someone help me out? It's probably an obvious mistake but I'm a total noob. Thanks in advance!
Exception in thread "main" java.lang.IllegalAccessError: class Game tried to access field Hero.Level (Game is in unnamed module of loader com.sun.tools.javac.launcher.Main$MemoryClassLoader @76b10754; Hero is in unnamed module of loader 'app') at Game.main(Game.java:9)
public class Game {
public static void main(String[] args){
Hero Tim = new Hero();
Tim.nameChar("Tim");
System.out.println("Dit is " + Tim.Level);
}
}
public class Hero{
String Character;
int Hitpoints;
int Attack;
int Experience;
int Potions;
int Level;
public Hero(){
Character = "Unnamed";
Hitpoints = 100;
Attack = 10;
Experience = 0;
Potions = 1;
Level = 1;
}
public void nameChar(String inputName){
this.Character = inputName;
}
public void checkLVL(){
if(Experience >= 100){
Level += 1;
}
}
}