3

My code is easily compiling over CMD (I'm using Windows) but doesn't compile in eclipse.

Please check the screenshot attached.

enter image description here

I read somewhere that I need to do some run configurations or add some JARS or external JARS but that all went over my head.

Note: I'm new to java so please be a bit elaborated :) THANK YOU! :D

Here is a screenshot of Problem tab in Eclipse: enter image description here

6
  • You must ensure that you add the location of your .class file to your classpath.
    – Rakesh KR
    Mar 31, 2014 at 7:15
  • 3
    You see that big exclamation point in the Package Explorer? That indicates a major problem with your project (not just one file), and you should look at that Problems view. Most likely, you don't have the JDK installed or configured correctly. Mar 31, 2014 at 7:16
  • possible duplicate of Error: Could not find or load main class
    – Rakesh KR
    Mar 31, 2014 at 7:17
  • @chrylis - The code compiles with CMD and I've set up environment variables as well. Could you please explain how do I achieve this?
    – mehulmpt
    Mar 31, 2014 at 7:20
  • @MehulMohan - Why not right click on your proj, open the build path and see for yourself? Mar 31, 2014 at 7:20

10 Answers 10

4

You need to mark your class as public so that runtime is able to call & execute it.

EDIT: So with the new image in your question, i can see that your JRE mapping is not correct under your project settings. Here is how you can update that:

Right click on project -> Java Build Path -> Libraries tab -> double click listed JRE library -> select the appropriate JRE

5
  • Note the build blocker. I suspect a missing JDK. Mar 31, 2014 at 7:17
  • I've downloaded the latest JDK Version 1.8.0 and latest Java Runtime V. 8. It works with CMD but doesn't work with Eclipse
    – mehulmpt
    Mar 31, 2014 at 7:17
  • Could you please provide me any link or screenshots to correctly map JRE in the settings?
    – mehulmpt
    Mar 31, 2014 at 7:18
  • Aha.. Thank you man. Here it works: Right click on project -> Java Build Path -> Libraries tab -> double click listed JRE library -> Select Workspace Default JRE (jre8)
    – mehulmpt
    Mar 31, 2014 at 7:22
  • @JunedAhsan - Yeah sure, but stackoverflow says me to wait 3 minutes to mark this answer complete :)
    – mehulmpt
    Mar 31, 2014 at 7:25
0

Where is your JRE? Add JRE by locating in windows. Click window preference and select installed JRE from java and choose jre environment.

1
  • ? Please explain, as I said, I'm a bit new to java. I've just configured my Environment Paths and it works like a charm through CMD.
    – mehulmpt
    Mar 31, 2014 at 7:17
0

Your Class name in Small Letters .Change the Name 'hello' in to Hello .

You need to change your file name and class as "Hello"

0

In my case, it was because there was a bug in Apache TomEE server. Going to Eclipse preferences and removing the TomEE server and replacing it with Tomcat 7 server and in the same dialog box, changing the JRE version to the jre7 which I installed (instead of choosing the workbench's JRE) helped solve the problem.

0

I also ran into a similar problem on my Ubuntu 14.04 after updating my system. So what I did was simply created a new workspace and imported my projects in it. Then it started working again.

0

Right click on project, go to properties/java compiler/enable project specific settings/select the jdk with which you want to compile, then check use default compilance setting. Now your program will compile without the error.

0

Reason:

This error occurs when JVM unable to load class at runtime. Generally because in eclipse JDK compiler set to some older JDK version and eclipse is trying to run in latest JRE version.

Solution:

  • In eclipse preference (Java -> Compiler) please set appropriate JDK version.
  • In eclipse preference (Java -> Installed JREs) Please set same JRE.
0

enter image description here Red exclaimation mark in your Package Explorer==> Project name shows that your whole project build has issue. It occurs when your eclipse/compiler is either pointing to wrong JRE/JDK path:

Here is the solution that worked form:

  1. Recently you might have updated your system's JDK but your Eclipse project is still pointing to older version. Or you misplaced some of the .jar which is used by your project.

Right click on your project>>properties>>JavaBuildPath>>Libraries.

Remove the jar which is having a red flag on it. If you still have the problem try below solution, this worked for me when i faced this problem second time:

right-click project>>Properties>>Java Build Path>>Libraries, Remove and Add Library. (Choose the JRE System Library )

0

I used to get this error. Basically there was a red cross sign on my Project name while I was getting this error. I deleted the project and defined a new project and the problem was solved just like that.

1
  • That answer should go to comments.
    – sg7
    Mar 11, 2018 at 17:55
0

When you type the project name, select Use default JRE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.