This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer (Exam 1Z0-830) Java SE 17 Developer (Exam 1Z0-829) Programmer’s Guide and have Khalid Mughal and Vasily Strelnikov on-line!
See this thread for details.
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

can't run from the command line to save life

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I keep getting this- java.lang.NoClassDefFoundError: Init

caused by: java.lang.ClassNotFoundException: Init
at: java.net.URLClassLoader$1.run<Unknown Source>
at: java.security.AccessController.doPriveleged<Native Method>
at: java.net.URLClassLoader.findClass<Unkown Source>
at: java.lang.ClassLoader.loadClass<Unkown Source>
at: Sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Init. Program will exit.

I have a classpath problem perhaps? If so then I don't know how to fix it. I tried to put the dot in the claspath that tells the compiler to search the current directory but it's more of the same.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What command are you entering, exactly? Also describe the directory layout (where the various involved files are).
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Face it, dont run from it

The error mentioned is java.lang.NoClassDefFoundError
it is as simple as it says: No Class Defination was found,
it is not finding a class named "Init"

Where is it ?
Do you have a class named "Init"
Are you using some jar containing a classname "Init"

I believe this is a this is a classpath related issue too
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be it's just because the file name and the class name that file contains.
Check whether the file name and the class name given in that file name are same.
This may be another case of getting error.(If i'm not wrong)
 
Marcus Deviln
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when I type: dir myProject at the command line it shows the myProject directory and sure enough within it is the Init file

Directory of C:\Users\marcus\myProject

11/30/2009 12:56 AM <DIR> .
11/30/2009 12:56 AM <DIR> ..
03/25/2009 11:07 PM 670 Dates3.java
01/29/2009 10:59 AM 0 dir
03/25/2009 11:08 PM 435 Init.java
01/29/2009 11:12 AM 0 javac
04/27/2009 04:18 PM 76,658,072 jdk-6u13-window
04/28/2009 09:53 AM 347 RegexSmall.java
03/25/2009 11:14 PM 634 ScanNext.java
04/28/2009 09:41 AM 796 Values.java
8 File(s) 76,660,954 bytes
2 Dir(s) 288,348,602,368 bytes free
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are getting a ClassNotFoundException. The file being looked for is not Init.java, but Init.class.
You didn't answer Ulf's question : What command are you entering, exactly ?
 
Marcus Deviln
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm entering: java Init -to answer your question
 
Sheriff
Posts: 22849
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you compile your Java file?
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Removed, to start in a new post, apologies.
 
Marshal
Posts: 80656
477
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David Thomas, please don't post what may be an unrelated question in somebody else's thread. This is regarded as hi-jacking, since it may prevent the original poster from having his question answered.

Please everybody only answer the original question, otherwise I shall pull rank and start deleting posts.
 
David Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
do you have a package in your Class for example

package a

class example

then try java -cp c:\xxxxx a.class

or even java a.class, in your case package.init

had a similar problem in which I had a\class ! and changed it to a.class and it worked.
 
Campbell Ritchie
Marshal
Posts: 80656
477
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good point, checking about package names.
 
Marcus Deviln
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Microsoft Windows [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.

C:\Users\marcus>java myProject1.Init
Exception in thread "main" java.lang.NoClassDefFoundError: myProject1/Init
Caused by: java.lang.ClassNotFoundException: myProject1.Init
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: myProject1.Init. Program will exit.

C:\Users\marcus>javac myProject1.Init /** Here I tried to compile but javac is not known. Am I not using the correct compilation command? **/
'javac' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\marcus>cd myProject1 // Here I guess I'm trying to change the current directory
The system cannot find the path specified.

C:\Users\marcus>-cp myProject1.Init /*I'm sure my use of classpath is not right. I'm trying to call the class by it's fully qualified name...Perhaps I need an absolute path??*/
'-cp' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\marcus>




The preceding is the source code located in:C:\Users\marcus\myProject
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic