Skip to content
Sign upLog in
← Back to Community

How to change the file name without error?(java)

Profile icon
samjh8xie

(I'm a new coder so I might not know a lot.) Basically, I changed the class from "public class Main" to "public class emails". I then changed the file name to "emails.java" too, but when I ran the code, it said "unable to run, main file "Main.java" not found." It kept on saying this after everything I tried. How can I stop this?
Also, whenever I add a new file to try to start over, it just prints the code from the Main.java file no matter what I do.

image

Answered by JacobMcPherson1 [earned 5 cycles]
View Answer
Voters
Profile icon
TerrorKid1
Profile icon
samjh8xie
Comments
hotnewtop
Profile icon
JacobMcPherson1

make a file called '.replit' and type run="javac emails.java && java emails" and that should fix it

Profile icon
samjh8xie

@JacobMcPherson1
Thanks I appreciate it! Do I have to do this for every repl?

Profile icon
JacobMcPherson1

@samjh8xie
Yeah

Profile icon
SixBeeps

To further elaborate on what

@JacobMcPherson1
said, the reason why this happens is because Replit maps a console command to the run button for every language. By default, this command compiles a file named Main.java and then runs it. If you rename the already-existing Main.java file that comes with the Repl, that file will no longer exist, and the command will fail. By retting the command manually in the .replit file, you are then able to map a different file name to compile and run.

This is the best option here since then you won't have to type the commands each time you want to run the program, but it's certainly not your only option. Throughout APCSA, I would create a new Java file for the runner class instead of using Main, then execute the runner's main method from the Main class' main method.

Profile icon
samjh8xie

@SixBeeps
ok thanks