I am trying to write a program, but I’m getting this compiler error:
Main.java:1: error: class WeatherArray is public, should be declared in a file named WeatherArray.java
public class WeatherArray {
^
1 error
I have checked my file names, and my public class is the same as my .java file.
How can I fix this?
Here is my code:
public class WeatherArray {
public static void main(String[] args) {
// ...
}
}
Name of public class must match the name of .java file in which it is placed (like
public class Foo{}must be placed inFoo.javafile). So either:Main.javatoWeatherArray.javapublic class WeatherArray {topublic class Main {