Running Java Problem (New)

Last week I had the following problem, which I solved with help from the Experts:
I am new to Java. Here is my problem I get the error message when I try to run javac. I have jdk1.6.0_06 loctaed in my program files/Java. I checked and I have javac located in the bin of the jdk1.60_06 file. I tried changing the path to c:\program files\java\jdk1.6.0_0\bin but still get the error. Is this the wrong path?

When I go back and insert javac I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError:
I have not changed my PATH, which is "c:\program files\java\jdk1.6.0_06\bin\";C:\GMX
bdiddy05Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
CEHJConnect With a Mentor Commented:
Looks like your installation is screwed. Uninstall all Javas and then install the latest JDK you can
0
 
CEHJCommented:
That's not a PATH problem, it's a CLASSPATH problem. What command are you executing and what does

echo %CLASSPATH%

give you?
0
 
shaz_Commented:
your classpath variable does not have the folder where you have created your ".java" file and where your generated byte code (.class file) is.. hence when u try to run it .. u get that error
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
shaz_Commented:
if u havent already created the classpath variable u can do so by creating something like....
CLASSPATH=.;c:\programme\jboss\lib;c:\programme\
j2sdk1.4.2_08\lib;c:\programme\j2sdk1.4.2_08\jre\lib;


note the "." after equals... required


or u can try running the file like
java -classpath . classname
0
 
CEHJCommented:
It's not actually necessary to specify a classpath explicitly at all and it usually isn't a good idea to have a fixed one
0
 
CEHJCommented:
>>It's not actually necessary to specify a classpath explicitly at all

should have been

It's often not actually necessary to specify a classpath explicitly at all
0
 
bdiddy05Author Commented:
i get .;c:\programme\jboss\lib;c:\programme\
j2sdk1.4.2_08\lib;c:\programme\j2sdk1.4.2_08\jre\lib; after inputting echo %CLASSPATH%
0
 
CEHJCommented:
What about my first question?
0
 
bdiddy05Author Commented:
javac
0
 
CEHJCommented:
The full command please. javac on its own just produces an error (usage) message
0
 
bdiddy05Author Commented:
javac classname.java
0
 
CEHJCommented:
Could you post the first few lines of classname.java?
0
 
bdiddy05Author Commented:
import java. io. *;
import java. text. DecimalFormat;
public class MC
{
public static void main (String[] args) throws IOException
{
0
 
CEHJCommented:
You need to execute

javac MC.java

Before doing so, change to the directory containing that file
0
 
bdiddy05Author Commented:
I did that javac.MC.jav

What do you exactly mean by changing the directory?
0
 
CEHJCommented:
You need to be in the same directory as the file in the console
0
 
bdiddy05Author Commented:
It is in the local c drive
0
 
CEHJCommented:
Please post the results of the following command

dir C:\MC.java

0
 
bdiddy05Author Commented:
File not found
0
 
CEHJCommented:
Then the file is not in the local C: drive. Where is it?
0
 
bdiddy05Author Commented:
C:\Documents and Settings\Owner>cd C:\Javas
C:\Javas.dir
Volume in drice C has no label.
Volume Serial Numer is D006-E60E
Directory of C:\Javas
6/23/2008 3:36 pm <DIR>
6/23/2008 3:36pm <DIR>
6/23/2008 3:36 pm 1,677 MC.java
1 file<s> 1,677 bytes
2 dir<s> 49,871,755,648, bytes free
C:\Javas>
0
 
CEHJCommented:
OK, so now you can do


C:\Javas>javac MC.java
0
 
bdiddy05Author Commented:
I tried that and still getting the same error.
0
 
CEHJCommented:
Please paste into the code snippet window the exact output you get when you try that
0
 
bdiddy05Author Commented:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
 
C:\Documents and Settings\Owner>cd C:\Javas
 
C:\Javas>dir
 Volume in drive C has no label.
 Volume Serial Number is D006-E60E
 
 Directory of C:\Javas
 
06/23/2008  03:36 PM    <DIR>          .
06/23/2008  03:36 PM    <DIR>          ..
06/23/2008  03:36 PM             1,677 MC.java
               1 File(s)          1,677 bytes
               2 Dir(s)  49,782,960,128 bytes free
 
C:\Javas>javac MC.java
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/M
ain
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
 
 
C:\Javas>

Open in new window

0
 
CEHJCommented:
Before doing

>>C:\Javas>javac MC.java

Try doing

C:\Javas>set CLASSPATH=
0
 
bdiddy05Author Commented:
Nope, say error message.
0
 
bdiddy05Author Commented:
Here is my classpath:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
 
C:\Documents and Settings\Owner>echo %CLASSPATH%
.;c:\programme\jboss\lib;c:\programme\j2sdk1.4.2_08\lib;c:\programme\j2sdk1.4.2_
08\jre\lib;
 
C:\Documents and Settings\Owner>

Open in new window

0
 
CEHJCommented:
You have the wrong classpath. Unset it as i said or do

javac -classpath C:\javas MC.java
0
 
bdiddy05Author Commented:
So I should set the CLASSPATH as javac -classpath C:\javas MC.Java?
If so should I include " at the beginning and end, and should the j in javas be capitalized?
0
 
CEHJCommented:
>>If so should I include " at the beginning and end, and should the j in javas be capitalized?

You don't need quotes - there are no spaces in the path. Strictly the 'J' should be a capital, yes
0
 
bdiddy05Author Commented:
I am still getting the same error message:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
 
C:\Documents and Settings\Owner>cd C:\\Javas
 
C:\Javas>dir
 Volume in drive C has no label.
 Volume Serial Number is D006-E60E
 
 Directory of C:\Javas
 
06/23/2008  03:36 PM    <DIR>          .
06/23/2008  03:36 PM    <DIR>          ..
06/23/2008  03:36 PM             1,677 MC.java
               1 File(s)          1,677 bytes
               2 Dir(s)  49,936,957,440 bytes free
 
C:\Javas>javac MC.java
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/M
ain
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
 
C:\Javas>echo %CLASSPATH%
javac-classpath C:\Javas MC.java
 
C:\Javas>

Open in new window

0
 
CEHJCommented:
>>javac-classpath C:\Javas MC.java

There's a space missing in that command. It should be

javac -classpath C:\Javas MC.java
0
 
bdiddy05Author Commented:
Still same problem:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
 
C:\Documents and Settings\Owner> echo %CLASSPATH%
javac -classpath C:\Javas MC.java
 
C:\Documents and Settings\Owner>cd C:\Javas
 
C:\Javas>dir
 Volume in drive C has no label.
 Volume Serial Number is D006-E60E
 
 Directory of C:\Javas
 
06/23/2008  05:38 PM    <DIR>          .
06/23/2008  05:38 PM    <DIR>          ..
06/23/2008  05:38 PM    <DIR>          jdk1.6.0_06
06/23/2008  03:36 PM             1,677 MC.java
               1 File(s)          1,677 bytes
               3 Dir(s)  49,879,453,696 bytes free
 
C:\Javas>javac MC.java
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/M
ain
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
 
C:\Javas>

Open in new window

0
 
CEHJCommented:
>>C:\Javas>javac MC.java

You're still not running the command i recommended
0
 
bdiddy05Author Commented:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
 
C:\Documents and Settings\Owner>echo %CLASSPATH%
javac -classpath C:\javas MC.java
 
C:\Documents and Settings\Owner>cd C:\Javas
 
C:\Javas>dir
 Volume in drive C has no label.
 Volume Serial Number is D006-E60E
 
 Directory of C:\Javas
 
06/23/2008  05:38 PM    <DIR>          .
06/23/2008  05:38 PM    <DIR>          ..
06/23/2008  05:38 PM    <DIR>          jdk1.6.0_06
06/23/2008  03:36 PM             1,677 MC.java
               1 File(s)          1,677 bytes
               3 Dir(s)  49,876,733,952 bytes free
 
C:\Javas>javac MC.java
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/M
ain
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
 
C:\Javas>

Open in new window

0
 
CEHJCommented:
The command is

C:\Javas>javac -classpath C:\Javas MC.java

NOT

C:\Javas>javac MC.java
0
 
bdiddy05Author Commented:
Before I go any further let me clarify:
CLASSPATH: C:\Javas>javac -classpath C:\Javas MC.java
0
 
CEHJCommented:
Just enter

javac -classpath C:\Javas MC.java

at the command prompt and post the result
0
 
bdiddy05Author Commented:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
 
C:\Documents and Settings\Owner>javac -classpath C:\Javas MC.java
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/M
ain
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
 
C:\Documents and Settings\Owner>

Open in new window

0
 
objectsCommented:
As I suggested in your previous question, your classpath does not neet to contain anything (and in it shouldn't need to).

0
 
objectsCommented:
try running:

javac -verbose MC.java

and tell me the output.

Did you install 1.4 for a reason? It may have screwed up your 1.6.

0
 
bdiddy05Author Commented:
I uninstalled and reinstalled Java and now it works.
Thanks CEHJ
0
 
bdiddy05Author Commented:
Thank you so much. You were really helpful and patient.
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.