I'm working on my code, to call some constructors from classes I created.
I'm sorry if my question is easy, but I tried to search everywhere and didn't figure out the answer.
On the other hand, all my classes are working well without any error.
When I need to call the constructor from the main class, it's giving me an error.
non-static variable this cannot be referred from a static context.
I will just post the first class I'm calling and having an error.
public class Test1 {
static int nextPers = 1;
public class Person{
private int persID;
private String persName;
private String email;
Person(int persID, String persName, String email){
persID = nextPers;
nextPers++;
this.persName = persName;
this.email = email;
}
public static void main(String [] args){
Person per = new Person(1 , "Raphael" , "meh@hotmail.com");
}
}
I cannot continue, the program is asking me to put static
variables, and I cannot figure my error because when I write static
before the variable, it's creating another error.