Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cannot find class error  RSS feed

 
hamza mohamed ansari
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
error exception in thread mainException in thread "main" java.lang.NoClassDefFoundError: Main/class

code:

it compiled successfully...class file and java file stored in desktop...
 
Campbell Ritchie
Marshal
Posts: 55745
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please don’t add unrelated posts to an old thread. Fortunately I can make a new thread from your post.
hamza mohamed ansari wrote: . . . it compiled successfully...class file and java file stored in desktop...
That is not a good idea. You ought not to store lots of things on the desktop. I suggest you try what it says here, making a java directory inside the default directory the command window uses (probably My documents on a Windows box). Move the .java file there, and delete the .class file.
I think the problem is that you are compiling the class with a package name, so the class is not called BeerSong. It is called chap01.BeerSong. Nor is it called Main.
Suggest:
  • 1: Go back to the .java file and edit it, in the new folder.
  • 2: Delete the line saying package chap01; and save file.
  • 3: Compile the class again with javac BeerSong.java
  • 4: Execute it with java Beersong
  •  
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!