• Register
3 votes


Hello Kodlogs,

I am a novice Java programmer. I just wrote my very first program a few minutes earlier. Now I want to write a program that can add two different integer numbers for me.
I guess I done my coding well but it says something wrong with my writing and throws back an error: “at least one public class is required in the main file

Please find my code snippet below to understand my problem well.

Thanks all.

class AddingNumbers{
     public static void main(String []args){
         int x = 10;
         int y = 15;
         int sum = x+y;
        System.out.println("Sum is: " + sum);


12 7 7
15,250 points

Please log in or register to answer this question.

1 Answer

0 votes


Hello Gavin, I hope you are enjoying programming with problem-solving. The problem occurred in the very first line of your program.

In java, you need to have at least one public class in your program otherwise it not gonna run. You may have multiple public classes but mandatory is t least one. I hope you get my point. Let’s write the program again with a public class,

public class AddingNumbers{
     public static void main(String []args){
         int x = 10;
         int y = 15;
         int sum = x+y;
        System.out.println("Sum is: " + sum);

Now your program looks good and you are all set to go. This program should compile error-free and give an output:

Sum is: 25


13 9 6
94,240 points

Related questions

0 votes
1 answer 28 views
Hi, when i try to execute this code i always get the error message from above, and i really want to know why, already tried to put a “public class XXXX” before the code, but not work anyway. public static String invertirPalabras(String cadena) { cadena += " "; String ... + palabra; if (cadena.charAt(i) == ' ') { nuevaCadena += palabra; palabra = ""; } } return nuevaCadena.trim(); }
asked Aug 2, 2020 Daniel Aguilar
0 votes
1 answer 43 views
Problem: Hi there! I have been learning to program for a long time now and I recently learned inheritance in Java. I wrote the following program for practice: class Institutions { public void print_institutions() { System.out.println("This is an institution"); } } class ... , I have no idea what is causing this error. Can anybody here please clarify the cause of the error and its solution? Thanks!
asked Dec 29, 2020 Code Learner 6k points
1 vote
1 answer 20 views
Problem: I Created a Loan.java and compile it with JDK 1.6 and Run Loan.class with JRE 1.5. C:\Program Files\Java\jre1.5.0_06\bin>java -version java version "1.5.0_06" The following thing gives an error message: C:\Program Files\Java ... Source)         at java.net.URLClassLoader.defineClass(Unknown Source)         at java.net.URLClassLoader.access$100(Unknown Source) what should i do next ..
asked Mar 27, 2020 LizzyM 6.1k points
1 vote
1 answer 31 views
Problem: I am totally new in programming language. So I tried to write a program using: public static void main(String args[]) But it seems to give error : public static void main(String args[]) ^ IndentationError: unexpected indent What should I do?
asked Apr 2, 2020 LizzyM 6.1k points
0 votes
1 answer 58 views
Problem : I am facing following Error. Status 1 error, param missing, error because at least one required parameter is missing. Can anybody tell me the correct status code to give when the parameter is missing from the request? Is 400 the correct one? Or is it 404? [GET /search?q=ok] => 200 OK [GET /search] => 400 Bad Request? or 404 Not Found? Or 422 Unprocessable Entity? Others?
asked Dec 2, 2019 alecxe 7.5k points
0 votes
1 answer 11 views
java file with a default class access specifier get compiled?
asked Jan 24 TeamScript 13.5k points
0 votes
1 answer 44 views
How can I fix this?
asked Dec 27, 2020 TeamScript 13.5k points
0 votes
3 answers 108 views
Problem: When the class name and the filename of a given Java program doesn’t match I get this error. Considering an example where file name is bal.java: public class Bal { public static void main(String[] args) { System.out.println("Hello, chutmarani!"); } } 1 error found : File:bal.java [line 1] Error: class Bal is public, should be declared in a file named bal.java Can anyone help?
asked Mar 23, 2020 LizzyM 6.1k points
0 votes
1 answer 13 views
I'm sorry if this question is of low quality, but I really need clarification on this. I hope experts in Java will help me.
asked Feb 13 TeamScript 13.5k points