1

I'm asking this question even though it has already been asked many times because I didn't find a solution after hours of searching.

I'm using Eclipse to learn Java. Last week everything worked properly. I could run whatever I wrote. Then today, I opened Eclipse, wrote some lines and when I tried to run it, I got an error:

Error: Could not find or load main class test.ArrayTest
Caused by: java.lang.ClassNotFoundException: test.ArrayTest

But that's not all : every project in my workspace is having the same issue. I can't run anything. At first I thought it was because I made a mistake at Eclipse start, so I closed it and re-opened it, but I was in the correct workspace.

I've tried to clean/rebuild it, doesn't work.
I've tried to mess with Properties > Java Build Path, doesn't work.
I've tried to create a new project with a simple 'Hello World', doesn't work.

package Hello;

public class Main
{
    public static void main(String[] args)
    {
        System.out.println("Hello World");
    }
}

What I have in package explorer.

Console display.

The thing that suprises me the most is that I don't think I've done anything that can mess with Eclipse between the moment it was working and now.

Does someone have another idea ?

Abra
  • 19,142
  • 7
  • 29
  • 41
HellNoki
  • 19
  • 2
  • 1
    Obviously, you are attempting to execute a wrong class (test.ArrayTest), so you should check your Eclipse run configurations (Menu Run -> Run Configurations) – Gyro Gearless Nov 25 '19 at 10:14
  • Have you thoroughly explored the solutions presented here: https://stackoverflow.com/questions/10356854/eclipse-cant-find-load-main-class?rq=1? – AnonymousAngelo Nov 25 '19 at 10:33
  • The test.ArrayTest class was in another project and how I first saw that run problem, the Hello World one is just for testing purpose. I've tried to change Run Configurations, but everything seems normal. Sorry for the image, I'll be careful next time n_n". As for the solutions, I've tried a new project, a whole new workspace with a clean .metadata, changing Build Path properties, but nothing works :/ – HellNoki Nov 25 '19 at 10:55
  • Just an information, as per Java's naming conventions you should start your package name with a small letter like it should be `hello`, not `Hello`. It might cause some confusion, between a class name and package name. – gprathour Nov 25 '19 at 12:45

2 Answers2

0

I think I found the root of the problem !

The path to my workspace was containing a letter with an accent ('Bibliothèque' by default with Windows 7+ in french...), so I tried to create a new workspace outside of it, and it worked !

I'm not a 100% sure it was really it, but since it worked, it's worth sharing.

HellNoki
  • 19
  • 2
0

Probably you have disconected JDK in project. Try open conextual menu on project (right mouse button) properties/Java Build Path/Libraries

check is correct JDK or remove then: [Add Library] / JRE System Library/ Alternate JRE/ [Installed JREs] / [Add] / Standard VM / [directory] select path to your JDK (not JRE) and confirm, select checkbox your new jdk and [Apply and close] on select list choose your new jdk and [Finish] and [Apply and Close]

should works. I have sometimes this problems. It's Eclipse

Victor1125
  • 642
  • 5
  • 16