Ask coding questions

← Back to all posts
I keep getting cant find main file
Wavykennyy (0)

I keep getting main file error

Comments
hotnewtop
SixBeeps (5222)

Note that although the solution @ANDREWVOSS provided does make the code run, you might find it better to keep your working file Merry.java and the classname Merry. From there, you can invoke Merry.main(args) from Main.java to call the main method. This is what I did for both APCSA and my Data Structures course because they wanted the class names to stay the same.

ANDREWVOSS (187)

@SixBeeps That's a much better solution. I honestly don't know much about Java.

ANDREWVOSS (187)

Rename Merry.java to Main.java

Wavykennyy (0)

@ANDREWVOSS I did and I get this error: class Merry is public, should be declared in a file named Merry.java
public class Merry {

ANDREWVOSS (187)

@Wavykennyy then rename Merry to Main

ANDREWVOSS (187)

@Wavykennyy and rename sayMerry() to main(string[] args)

ANDREWVOSS (187)

@Wavykennyy like this:

class Main {
  public static void main(String[] args) {
    
    // Prints I wish you a merry Christmas
    System.out.println("We wish you a merry Christmas");
  }
}