Alexandre Blanchet
Alexandre Blanchet

Reputation: 107

Can't seem to resolve the error "Could not find or load main class”

I've been trying to execute the code someone else gave me. I'm 100% sure it should compile. I'm following the common method to compile and execute this java code, but it's just not working for me. I've already execute Java code in the past, but I can't seem to find a way around unfortunatly.

What I usually do:

  1. Find my directory and make it my current directory
  2. set path=%path%;C:\Program Files\Java\jdk1.5.0_09\bin
  3. "javac *.java" to compile everything without having trouble with dependencies.
  4. "java Jeu" where Jeu is my class with the public static void main

Here is a simplify version of the "Jeu class" code:

package core;

import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.util.Arrays;
import java.util.List;

public class Jeu {

    public static void main(String [ ] args) {

         // stuff
    }   
}

After reading some tips online, I tried "java core.Jeu" or even "java core/Jeu" without success. Still the same message "Could not find or load main class”.

The problem is not the java compiler(set path command). It's totally working because when I tried to compile my classes one at a time, the cmd showed me a compilation error about dependencies. Using "javac *.java" fixed it

Since the class "Jeu" is dependant from other class like "Voiture", could the problem be that the "Jeu.java" didn't compile correctly even though the "Jeu.class" exist?

Upvotes: 1

Views: 539

Answers (2)

rpfun12
rpfun12

Reputation: 89

Make sure you current directory in the classpath java -cp . core.Jeu

. will include the current directory in the class path. Or you can include the absolute path as well

Upvotes: 0

lukeg
lukeg

Reputation: 4399

Is your core.Jeu class in core directory? Are you calling java from outside of core directory?

Upvotes: 1

Related Questions