Solved

Running Java Problem (New)

Posted on 2008-06-23
45
230 Views
Last Modified: 2013-11-23
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
0
Comment
Question by:bdiddy05
  • 21
  • 20
  • 2
  • +1
45 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 21847013
That's not a PATH problem, it's a CLASSPATH problem. What command are you executing and what does

echo %CLASSPATH%

give you?
0
 
LVL 3

Expert Comment

by:shaz_
ID: 21847044
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
 
LVL 3

Expert Comment

by:shaz_
ID: 21847064
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 86

Expert Comment

by:CEHJ
ID: 21847136
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 21847219
>>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
 

Author Comment

by:bdiddy05
ID: 21847367
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 21847414
What about my first question?
0
 

Author Comment

by:bdiddy05
ID: 21847427
javac
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21847563
The full command please. javac on its own just produces an error (usage) message
0
 

Author Comment

by:bdiddy05
ID: 21847616
javac classname.java
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21847693
Could you post the first few lines of classname.java?
0
 

Author Comment

by:bdiddy05
ID: 21847791
import java. io. *;
import java. text. DecimalFormat;
public class MC
{
public static void main (String[] args) throws IOException
{
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21847816
You need to execute

javac MC.java

Before doing so, change to the directory containing that file
0
 

Author Comment

by:bdiddy05
ID: 21849114
I did that javac.MC.jav

What do you exactly mean by changing the directory?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21849163
You need to be in the same directory as the file in the console
0
 

Author Comment

by:bdiddy05
ID: 21849528
It is in the local c drive
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21849717
Please post the results of the following command

dir C:\MC.java

0
 

Author Comment

by:bdiddy05
ID: 21849800
File not found
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21849825
Then the file is not in the local C: drive. Where is it?
0
 

Author Comment

by:bdiddy05
ID: 21849893
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 21849929
OK, so now you can do


C:\Javas>javac MC.java
0
 

Author Comment

by:bdiddy05
ID: 21849960
I tried that and still getting the same error.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21850019
Please paste into the code snippet window the exact output you get when you try that
0
 

Author Comment

by:bdiddy05
ID: 21850085

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
 
LVL 86

Expert Comment

by:CEHJ
ID: 21850163
Before doing

>>C:\Javas>javac MC.java

Try doing

C:\Javas>set CLASSPATH=
0
 

Author Comment

by:bdiddy05
ID: 21850189
Nope, say error message.
0
 

Author Comment

by:bdiddy05
ID: 21850206
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 21850284
You have the wrong classpath. Unset it as i said or do

javac -classpath C:\javas MC.java
0
 

Author Comment

by:bdiddy05
ID: 21850362
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 21850405
>>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
 

Author Comment

by:bdiddy05
ID: 21850600
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 21850651
>>javac-classpath C:\Javas MC.java

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

javac -classpath C:\Javas MC.java
0
 

Author Comment

by:bdiddy05
ID: 21850681
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 21850718
>>C:\Javas>javac MC.java

You're still not running the command i recommended
0
 

Author Comment

by:bdiddy05
ID: 21850768

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
 
LVL 86

Expert Comment

by:CEHJ
ID: 21850796
The command is

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

NOT

C:\Javas>javac MC.java
0
 

Author Comment

by:bdiddy05
ID: 21850836
Before I go any further let me clarify:
CLASSPATH: C:\Javas>javac -classpath C:\Javas MC.java
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21850875
Just enter

javac -classpath C:\Javas MC.java

at the command prompt and post the result
0
 

Author Comment

by:bdiddy05
ID: 21850889

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
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 21850924
Looks like your installation is screwed. Uninstall all Javas and then install the latest JDK you can
0
 
LVL 92

Expert Comment

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

0
 
LVL 92

Expert Comment

by:objects
ID: 21851125
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
 

Author Comment

by:bdiddy05
ID: 21851326
I uninstalled and reinstalled Java and now it works.
Thanks CEHJ
0
 

Author Closing Comment

by:bdiddy05
ID: 31469783
Thank you so much. You were really helpful and patient.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21860849
:-)
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question