7

I'm having trouble running a project in Eclipse 4.2. I have a Java program with one class titled Conversion. Eclipse builds the project fine. I'm able to run the program from the command line by navigating to /bin/ in the project's folder that's in the workspace and typing java Conversion.

However, when I try to run the program from Eclipse, I am shown Error: Could not find or load main class Conversion in the console.

The project name is 10.12.12: Project.

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Zach Latta
  • 3,251
  • 5
  • 26
  • 40

5 Answers5

6

It appears that the project is not part of the classpath.
Check in your Run Configuration->Classpath and if your project is not there, then add it under User Entries.

enter image description here

enter image description here

Cratylus
  • 52,998
  • 69
  • 209
  • 339
  • I believe my project is there. Here's a [screenshot](http://i.imgur.com/BMJME.png). – Zach Latta Sep 16 '12 at 09:18
  • @Crynix:I am not sure about this, but why is it showing the Converion folder twice? Is it like this for your working projects as well? – Cratylus Sep 16 '12 at 09:33
  • I'm not sure why it was doing that. I create a new project and copied and pasted the code from the old project into it. I'm still getting the same issue, although there are no longer two entries under User Entries. Here's a [screenshot](http://i.imgur.com/7qCJI.png). Also, I don't have any other projects than this one in Eclipse. – Zach Latta Sep 16 '12 at 09:41
  • @Crynix:No other project?Ok, try creating a Java project, create a `Hello` class **under package** `com` with a `main` that prints `Hello World`.Does this work? – Cratylus Sep 16 '12 at 09:47
  • @Crynix:No that should not matter.It should work also in the default package.What is the number `9.11.12`?Is it present in your working project? – Cratylus Sep 16 '12 at 09:54
  • That's the date of the project's creation. I had it there to keep track of my weekly assignments. – Zach Latta Sep 16 '12 at 09:55
  • @Crynix: **But** do you **also** have it on your working `Hello world` project? – Cratylus Sep 16 '12 at 09:57
  • I do not. Could that be the source of the issue? – Zach Latta Sep 16 '12 at 10:01
  • @Crynix:Yes.If you want to add some kind of numbering in your project do: `ProjectName_May_1`.The proper approach is to use source control. – Cratylus Sep 16 '12 at 10:04
5

Eclipse does not support the use of a colon or hyphen in project names. Colons appear to break the way it handles compilation.

The issue can be fixed by not using a colon in the project's name.

As noted in the comments, this may be a fault of Java 6. It is fixed in Java 7.

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
Zach Latta
  • 3,251
  • 5
  • 26
  • 40
  • I think Java 1.6 has an issue with it, rather than it being Eclipse's fault, because switching to 1.7 solved this for me. – djb Jul 03 '13 at 09:30
1

I understand the ':' was likely the case here, but I had a tangential issue that might help someone else.

I inherited a project and was having a similar issue. Dev/Debugging is on Mac/Win, and the TST/UAT/PRD environment is RHEL. Someone literally copied the systemd command line and left a '\' in the Debug arguments. The reason this was hard to find is that the lines wrap right at the -D, so the \ is the last char on a line, which looks OK under Linux. I fixed it like this...

In my case it was...

-Dlog4j.configurationFile=file:<PATH>/log4j2.xml \
-DCONFIG_PATH=...

Right-Click Project -> Run-As/Debug-As, click the Arguments Tab.
In the VM Arguments, look for \.  

HTH.

  • Could you please format and structure your answer a little bit more, especially the code snippets using Markdown? This makes it easier for all of us to follow your thoughts. – mle Mar 19 '19 at 17:03
0

Make sure the build path is configured properly in the eclipse. Paths for the external JAR files may be wrong.

rizwan
  • 511
  • 5
  • 8
-1

This Problem will accrues Saving file name one name and compile time u have gives another name. That time you will get that problem. Check the java file name once.

rolve
  • 10,083
  • 4
  • 55
  • 75