class Student {
private String firstName;
private String lastName;
public Student(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public void printFullName() {
System.out.println (this.firstName+" "+this.lastName);
}
}
public class Main {
public static void main(String[] args) {
Student[] students = new Student[] {
new Student("Morgan", "Freeman"),
new Student("Brad", "Pitt"),
new Student("Kevin", "Spacey")
};
for (Student s : students) {
s.printFullName();
}
}
}
I was learning java from learnjavaonline and this is the answer for one of the exercises. In their website the code runs without anyproblem, but when I ran in VScode (Java extension pack was installed and so was the latest version of Java) it returned me with the error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at Main.main(Student.java:15)
So can someone help me by pointing out what is the problem?
The code is perfectly fine. Just rename the file as Main.java and use some other IDE. I feel this might be some setting issue with VSCode. You have to resolve all workspace errors and make sure there is only one main(String args[]) function in your file.I too faced problem compiling a java file using java extension pack, it always showed build error but when click proceed it works. I strongly recommend you try eclipse. Or try using command line.
javac Main.javajava -c . MainIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With