-2

I am using Eclipse latest version and I am facing the error "Could not find or load main class" every time I run this simple code as a 'Java application'. I am new so don't know much about Java. i am looking forward to some help and please specify in detail. screenshot of run configurations window screenshot of Buildpath config. window

   class apples{
        public static void main(String[] args) {
        System.out.println("Hello, World");
          }
        }
Ahmad Irfan
  • 19
  • 1
  • 3

2 Answers2

1

This problem you may face when you provide two different names in the class name and the .java file. When you are compiling the code you have to give the filename and the JVM creates the .class file. But at the run time you have to provide the class name in which your main method is present(in you case apples.class).

Try to give the same name to your file as well as the class or run it with the class name you've given.

Soumyajit
  • 329
  • 1
  • 5
  • 16
0

Firstly, please check: eclipse docs

Secondly, check "Run Configurations". More information in this answer: Eclipse error “Could not find or load main class”

If all the solution doesn't work, you may try to check libraries:

  1. Right click your project, Build Path --> Configure Build Path --> Java Build Path --> Libraries
  2. Remove the missing libraries
  3. Go to your main class and try to run it again.

There are a lot of tips in the second link, some of them may help you.

Community
  • 1
  • 1
pobo
  • 7
  • 4