1

I'm using Eclipse and I've written a Java application using SWT. When Eclipse compiles my program, it renames my main file into 4 different files like this:

  • MainFile.class
  • MainFile$1.class
  • MainFile$2.class
  • MainFile$3.class

When I go to run this program from command line, I get

Could not find the main class: MainFile.class. Program will exit.

I really don't understand why this is happening.

Favonius
  • 13,959
  • 3
  • 55
  • 95
user1366697
  • 171
  • 2
  • 9
  • Can you show is the line from the command line that you ran to get this error? Like, `lowasser@gowers$ java MainFile` or whatever. – Louis Wasserman May 28 '12 at 15:27

1 Answers1

5

The $ classes are for anonymous inner classes and perfectly normal.

Could we see the command line you ran? You probably need to write java MainFile instead of java MainFile.class.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
Louis Wasserman
  • 191,574
  • 25
  • 345
  • 413
  • I've tried both. I'm glad that's normal although now I really don't know why it won't run from terminal. – user1366697 May 28 '12 at 15:17
  • Could you actually show us the command line in your question? That would help us figure out what's going on. – Louis Wasserman May 28 '12 at 15:18
  • @user, If your MainFile class is in a package, then you need to make sure you are saying `java my.package.MainFile` with the classpaths properly set. – Jeremy May 28 '12 at 15:24
  • In fact even the "anonymous" is misleading a little bit. For anonymous inner classes a number will be appended after the $, like in the sample. For non-anonymous inner classes the name will be used. – Hauke Ingmar Schmidt May 29 '12 at 08:43