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.
+Deviln+ The power of JAVA compels you!
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35252
7
posted
0
What command are you entering, exactly? Also describe the directory layout (where the various involved files are).
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
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
Joined: Jan 29, 2009
Posts: 39
posted
0
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
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 ?
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
Joined: Jan 13, 2010
Posts: 4
posted
0
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
Sheriff
Joined: Oct 13, 2005
Posts: 32708
4
posted
0
Good point, checking about package names.
Marcus Deviln
Ranch Hand
Joined: Jan 29, 2009
Posts: 39
posted
0
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