I know it's no longer an issue for the original poster but new programmers may run into this.

You likely forgot to add String[] args in your main method. This means the program will default to running another class, likely whatever was ran last.

public static void main(String[] args) {

}

This was a really basic issue that anyone with decent experience would likely not think of hence what I assume to be the reason for the lack of replies.

P.S. I just jumped back into coding and ran into this a couple minutes ago.

Answer from UnskilledUnityCoder on Stack Overflow
🌐
The Eclipse Foundation
eclipse.org › forums › index.php › t › 487572
Eclipse Community Forums: Newcomers » Eclipse wont run my class | The Eclipse Foundation
May 15, 2013 - The Eclipse Foundation - home to a global community, the Eclipse IDE, Jakarta EE and over 350 open source projects, including runtimes, tools and frameworks.
Discussions

Eclipse: Could not find or load main class?
Your current run configuration isn't pointing to the correct class file containing the main method you wish to run (ie. the class has been moved or deleted). Eclipse usually automatically creates your run configuration when you first run a program, but it can sometimes get messed up if you delete or move classes around. You can right click on the class file containing your main method in the package explorer on the left then go Run As -> Java Application, which creates a new run configuration. Another option is in that run configurations window you have open there, re-select the correct project and main class file. More on reddit.com
🌐 r/javahelp
10
1
May 28, 2018
Can't compile/run in Eclipse- Java - Stack Overflow
I'm trying to compile and run a simple program in Eclipse and whenever I hit run it says select what to run: and theres the option of two ant builds I have no clue what ant builds are or what to do... More on stackoverflow.com
🌐 stackoverflow.com
compilation - Eclipse won't compile/run java file - Stack Overflow
This is not required to run locally in Eclipse though. If your class is run-able. It looks like yours is, but we can not see all of it. If you look at your project build path do you have an output folder selected? If you check that folder have the compiled class files been put there? If not the something is not set in Eclpise for it to know to compile. You might check to see if auto build is set for your project. ... Hey thanks for your help! I created these java ... More on stackoverflow.com
🌐 stackoverflow.com
java - Eclipse can't find / load main class - Stack Overflow
My Eclipse (Indigo) was running just fine. I created a simple class Hello. It is placed in package cont in the folder ch13. However, when I try to run it from Eclipse I get info from Java Virtual Machine Launcher: CopyCould not find the main class: cont.Hello. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/javahelp › eclipse: could not find or load main class?
r/javahelp on Reddit: Eclipse: Could not find or load main class?
May 28, 2018 -

I've never gotten this issue before when running Java in Eclipse. Here is my run config and a simple main function to test. Any help would be great!

https://imgur.com/a/8yd6gp7

Top answer
1 of 2
2
Your current run configuration isn't pointing to the correct class file containing the main method you wish to run (ie. the class has been moved or deleted). Eclipse usually automatically creates your run configuration when you first run a program, but it can sometimes get messed up if you delete or move classes around. You can right click on the class file containing your main method in the package explorer on the left then go Run As -> Java Application, which creates a new run configuration. Another option is in that run configurations window you have open there, re-select the correct project and main class file.
2 of 2
1
It seems that you possibly have a screenshot of code in your post Eclipse: Could not find or load main class? in r/javahelp . Screenshots of code instead of actual code text is against the Code posting rules of /r/javahelp as is also outlined in the sidebar - Code posting. Never submit screenshots of code instead of code text! If you posted an image merely to illustrate something, kindly ignore this message and do not repost. Your post is still visible to others. I am a bot and cannot distinguish between code screenshots and other images. If you indeed did this wrong, please edit the post so that it uses one of the approved means of posting code. For small bits of code (less than 50 lines in total, single classes only), the default code formatter is fine (one blank line before the code, then 4 spaces before each line of code). Pastebin for programs that consist of a single class only Gist for multi-class programs, or programs that require additional files Github or Bitbucket repositories are also perfectly fine as are other dedicated source code hosting sites. Ideone for executable code snippets that use only the console Please do not reply to this message, because I am a bot. Talk-to-the-bot is the new talk-to-the-hand. If you instead want the classic talk-to-the-hand, just message the moderators. ;) I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
Java67
java67.com › 2016 › 09 › 3-ways-to-solve-eclipse-main-class-not-found-error-java.html
3 ways to solve Eclipse - main class not found error | Java67
I debug the Java application in Eclipse by right click and choose "Debug As Java program" and found that it was throwing ClassNotFoundEexception for a third-party class. It was a kind of breakthrough after wasting such a long time but still, the clue wasn't enough because the class belongs to one of the dependent JAR which was available in classpath but somehow Eclipse was not seeing it. My error was resolved after deleting the existing run configuration where the User entry was not pointing to the default classpath.
Find elsewhere
🌐
Coderanch
coderanch.com › t › 744642 › ide › code-running-Eclipse-main-method
why is the code not running in Eclipse when there is a main method? (IDEs and Version Control forum at Coderanch)
August 4, 2021 - Can someone tell me how I can make Eclipse run the above code? Tks. ... Well, first, you might want to clean up your indentations. It makes it confusing to read code that isn't consistently indented. Do that by clicking in the source code, then Ctrl-A to select All code in the pane and Ctrl-I to tell it to indent it properly. A Java project can actually contain more than one main() method, although only one per class...
🌐
Filo
askfilo.com › american national curriculum › smart solutions › why cant i run my current class in eclipse java it only runs a
why cant i run my current class in eclipse java it only runs a previous o..
February 26, 2026 - This issue usually occurs because ... not have a valid main method. Follow these steps to fix it: Ensure your current Java class contains the correct entry point. Without this, Eclipse cannot run the file as a Java ...
🌐
Stack Overflow
stackoverflow.com › questions › 74034896 › why-is-my-eclipse-java-program-not-running-error-message-error-could-not-fi
Why Is My Eclipse Java Program Not Running - Error Message: "Error: Could not find or load main class" - Stack Overflow
Double-check that the Installed JREs preference page has a valid Java 11 runtime defined. Eclipse uses Java to run itself, but you still have to tell it which JREs you want it to offer to compile your own projects against.
🌐
Reddit
reddit.com › r/learnjava › can't run java eclipse application, no error but some other application running
r/learnjava on Reddit: Can't run Java eclipse application, no error but some other application running
September 12, 2024 -

Hi,

I have written a simple Java application. However, when I execute the application, I get some other application being executed. My code is given below:

//Convert int to Integer
import javax.swing.*;
public class IntToInteger {
   int iA;
   IntToInteger(int iA){
   this.iA = iA;

}
    void ConvertIntToInteger(int iA){
       Integer iRes = Integer.valueOf(iA);
       JOptionPane.showMessageDialog(null, " "+ iRes);
    
    }
}

Some body please guide me.

The image is attached at:

https://ibb.co/r5dGVZt

Somebody please guide me.

Zulfi.

Top answer
1 of 4
4
You are definitely missing a main method in that class. I have not used Eclipse IDE in a while but I think if you add a main method to your class, there should be a small green run button that pops up next to it. If you try to run by pressing the run button on the top menu bar of the IDE I think it will run the last successful run configuration (probably some other project you ran before). So try adding: public static void main(String[] args) { IntToInteger program = new IntToInteger(42); program.ConvertIntToInteger(42); } There are some other things I would note regarding your code, first of all you are defining a class field called iA but in your ConvertIntToInteger method you are also defining a parameter called iA . This will shadow your class field iA and use the value you passed as a method argument instead (unless you do this.iA). So, you can probably either remove the class field and the parameter from the constructor of your class, or remove the parameter from your ConvertToInteger method. Also, in Java the convention is to start method names (except for constructors, of course) with a lower case letter.
2 of 4
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
Java-forums
java-forums.org › eclipse › 56141-eclipse-runs-previous-class-wont-run-current-class.html
Eclipse runs a previous class and won't run the current class
March 1, 2012 - The problem in this case was that I ran one class in a four class application without realizing there were three more classes in the application. The class I ran did not have a main method. Once I loaded the other three classes and started by running the class with the main method, it ran properly. willisduke3 ... I was facing the same issue, and after searching on several blogs which seemed to be talking way too techincal.. And some even called it as being an Eclipse bug.
Top answer
1 of 16
91

If you create a java class with public static void main(String[] args), Eclipse will run that main method for you by right clicking on the file itself, or on the file in the project explorer, then choosing:

"Run As" -> "Java Application."

Once you do this, Eclipse stores information about your class, so you can easily run the class again from the Run As menu (Green Play Button on the toolbar) or from the Run Configurations dialog.

If you subsequently MOVE the java class (manually, or however), then again choose

"Run As" -> "Java Application,"

from the new location, Eclipse will run the original stored configuration, attempt to invoke this class from its original location, which causes this error.


SOLUTION:
For me, the fix was to go to the run configurations, (Green Play Button -> Run Configurations) and remove all references to the class. The next time you run

"Run As" -> "Java Application"

Eclipse will write a new configuration for the moved class, and the error will go away.

2 of 16
75

tl;dr: Clean your entire Build Path and everything you ever added to it manually. This includes additional sources, Projects, Libraries.

  • Project -> Clean
  • Make sure Project -> Build automatically is active
  • Project -> Properties -> Java Build Path -> Libraries: Remove any external libs you have ever added. Don't remove standard libraries like the JRE System Library.
  • Try to run your main class now. The "class could not be found / load" error should be gone. Try adding your external libs/jars one after each other.

Reason behind this: The compiler had issues linking the libraries to the project. It failed and produced a wrong error message.

In my case, it should have been something like "Could not add AutoHotkey.dll to the build path" because that was what made the compiler fail.


If this is still not working, have a look at the built-in ErrorLog of Eclipse:

Window -> Show View -> General -> Error Log

🌐
Stack Overflow
stackoverflow.com › questions › 12232446 › program-in-eclipse-not-running
java - Program in Eclipse not Running - Stack Overflow
September 2, 2012 - I wonder if it is because I imported my files incorrectly or something that I forgot to install. Please tell me how I can make it work properly again. Thanks in advance. ... You most likely need to configure it to run with Java.
🌐
Quora
quora.com › Why-doesnt-a-Java-class-show-Run-as-Java-Application-in-Eclipse-IDE-when-the-main-method-arguments-is-int-args-rather-than-String-args
Why doesn't a Java class show 'Run as' --> 'Java Application' in Eclipse IDE when the main method arguments is 'int [] args' rather than 'String [] args'? - Quora
Answer (1 of 4): Because the Java virtual machine by convention expects the program entry point to have a method signature of public static void main(String[] args). That is the method the JVM is looking for when you tell it to execute a class from the console. A method with a signature of publ...
🌐
The Eclipse Foundation
eclipse.org › forums › index.php › t › 1098016
Eclipse Community Forums: Newcomers » Problem with running Java code | The Eclipse Foundation
The Eclipse Foundation - home to a global community, the Eclipse IDE, Jakarta EE and over 350 open source projects, including runtimes, tools and frameworks.