• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why on setting package javac gives noclassdeffound error?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


When I create a project with default package and include two files: one main class and other class which main depends on, then compile and run it from commandline without problem. But when I do same except creating and putting these two classes in a named package then it compiles but when I run it says noclassdeffound error. I cannot find any clear cut consistent solution for this.
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it says noclassdeffound error.


Can you copy the contents of the command prompt window where you entered the java command that shows the command and the directory where the command was issued.

If the class is in a package you need to use the full package/class name with the java command and the classpath must point to the folder containing the package folder.
 
Bartender
Posts: 242
27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How are you compiling this, and how are you referencing the main class?

If you're using a package manager like Maven, you can have Maven specify the main class like this:


If you're using built-in IntelliJ functions to specify the main class, you'll have to update those whenever you change the pathname of the main class

If using raw javac commands - ensure that you're typing the fully qualified classname. To do this, type "packageName.mainClass" for example.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic