Solution:
Name of public class should match the name of .java file in which it is placed (like public class Foo{}
should be placed in Foo.java
file). So either:
The name of the public class within a file has to be the similar as the name of that file.
Therefore in case your file declares class WeatherArray, it requires to be named WeatherArray.java
For example, I renamed my MainActivity
class to MainnActivity
only (!) in the code. I obtain this error instantly.
There is also a visual indicator in the Project tab of Android Studio - a class within a class, like you have nested classed, however with an error indicator.
You called your file as Main.java. name your file as WeatherArray.java and compile.
Your file is called Main.java where it must be
WeatherArray.java
I had the similar problem however solved it at the time I convinced that I didn't compile it with the appropriate casing. You may have been doing
A Java file can just have 1 public class in it. The name of that public class should be the similar as the filename.
To the file MyClass.java
must comprise a class MyClass
that may or may not be public. however it should not comprise a public class with any other name.
From my comprehension for same question, the name of the file must be the similar as the public class, and at the time i alter the class name to R_2 (i refactored the filename to R_2.java from R 2.java), it throws this error.
error: invalid method declaration; return type required