Why it could not find the main class?
Asked Answered
F

2

8

I have a very simple code:

package mygame;
public class RunGame {
    public static void main(String[] args) {
        System.out.println(args[0]);
    }
}

I can compile that code but I cannot run it. When I type "java RunGame" in the command line I get:

Exception in thread "main" java.lang.NoClassDefFoundError: RunGame (wrong name: mygame/RunGame).
....
Could not find the main class: RunGame. Program will exit.

Fulk answered 10/3, 2010 at 12:18 Comment(2)
What command line are you using to run your class?Sundstrom
I tried to run the program with "java RunGame" and it was the mistake. I needed to use "java mygame.RunGame".Fulk
C
8
java mygame.RunGame 

is the java executable syntax. i.e, java classname.qualified.with.full.packaging

Also what is the RunColoredTrails class in the output you have shown?

Corsetti answered 10/3, 2010 at 12:22 Comment(1)
It was a mistake. It should be "RunGame"Fulk
N
7

u might be trying
C:\your-java-directory-\mydir\> java RunGame right ?

remember RunGame is inside a package called mydir. so go one step back in ur execution path..

c:\your-java-directory\>

now compile and execute like this

c:\your-java-directory\> javac mydir\RunGame.java
c:\your-java-directory\> java mydir.RunGame

Numerary answered 10/3, 2010 at 12:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.