Wrox Programmer Forums
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 13th, 2006, 12:42 PM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Exception error

Whenever I try to run any of the examples in the book I get the following error:

C:\>java c:\java\programs\mathcalc
Exception in thread "main" java.lang.NoClassDefFoundError: c:\java\programs\mathcalc

I thought it might have something to do with the CLASSPATH but I have tried every classpath I can think of and still have the problem.



 
Old July 13th, 2006, 08:43 PM
Authorized User
 
Join Date: Dec 2005
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please make sure the class name is same as the java file name.

See below tutorial about how to write and compile first java class
http://www.developerzone.biz/index.p...=128&Itemid=36

JAVA Printer
http://www.javawisdom.com/
http://www.hotdir.biz/
 
Old July 14th, 2006, 03:39 PM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by lewright
 Whenever I try to run any of the examples in the book I get the following error:

C:\>java c:\java\programs\mathcalc
Exception in thread "main" java.lang.NoClassDefFoundError: c:\java\programs\mathcalc

I thought it might have something to do with the CLASSPATH but I have tried every classpath I can think of and still have the problem.

The Class and Java files have the same name.
Also, I can not see any thing wrong with programs, and here is one for example:


public class MathCalc
{
  public static void main (String[] args)
  {
    // Calculate the radius of a circle
    // which has an area of 100 square feet
    double radius = 0.0;
    double circleArea = 100.0;
    int feet = 0;
    int inches = 0;
    radius = Math.sqrt(circleArea/Math.PI);
    feet = (int)Math.floor(radius); // Get the whole feet and nothing but the

feet
    inches = (int)Math.round(12.0*(radius - feet));
    System.out.println("The radius of a circle with area " + circleArea +
                      " square feet is\n " + feet + " feet " + inches + "

inches");
  }
}

This thing is driving me nuts.

 
Old July 14th, 2006, 07:22 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you compiled the .java into a .class file yet? To do this, use the "javac" command, not "java". Once you have a .class file you can run "java mathcalc".

Jon Emerson
http://www.devexplore.com/developer/...jects.php?id=6
 
Old July 15th, 2006, 03:20 PM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by panacea
 Have you compiled the .java into a .class file yet? To do this, use the "javac" command, not "java". Once you have a .class file you can run "java mathcalc".

Jon Emerson
http://www.jonemerson.net/
Yes I have made the class file via the java command.
 
Old July 16th, 2006, 03:16 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ah, ok. Try running the "java" command from the folder that contains mathcalc.exe. For example:

C:\>cd java\programs
C:\java\programs\>java mathcalc

Jon Emerson
http://www.devexplore.com/developer/...jects.php?id=6
 
Old July 17th, 2006, 08:28 AM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by panacea
 Ah, ok. Try running the "java" command from the folder that contains mathcalc.exe. For example:

C:\>cd java\programs
C:\java\programs\>java mathcalc

Jon Emerson
http://www.devexplore.com/developer/...jects.php?id=6
I just did what you suggested and from what I got below I think I had better reload my JAVA software.

C:\>cd java\programs

C:\Java\Programs>java mathcalc
Exception in thread "main" java.lang.UnsupportedClassVersionError: mathcalc (Unsupported major.minor version 49.0)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknow n Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        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)

Thanks
 
Old July 17th, 2006, 03:51 PM
Registered User
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by lewright
 
Quote:
quote:Originally posted by panacea
Quote:
 Ah, ok. Try running the "java" command from the folder that contains mathcalc.exe. For example:

C:\>cd java\programs
C:\java\programs\>java mathcalc

Jon Emerson
http://www.devexplore.com/developer/...jects.php?id=6
I just did what you suggested and from what I got below I think I had better reload my JAVA software.

C:\>cd java\programs

C:\Java\Programs>java mathcalc
Exception in thread "main" java.lang.UnsupportedClassVersionError: mathcalc (Unsupported major.minor version 49.0)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknow n Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$100(Unknown Source)
        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)

Thanks
I reloaded the software and did what you last recommended and everything worked perfect. Thanks a lot for your suggestion.

Lee Wright
 
Old July 17th, 2006, 06:35 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No problem :). It seems like you were compiling your .java file with JDK 1.5, but then running it with JRE 1.4. In the future you probably don't need to reinstall Java -- just change your system PATH so that it points to the right runtime environment :).

Jon Emerson
http://www.jonemerson.net/





Similar Threads
Thread Thread Starter Forum Replies Last Post
error:Exception occurred hastikeyvan Classic ASP Professional 1 September 13th, 2006 04:40 AM
null exception error abhit_kumar JSP Basics 4 January 5th, 2005 05:26 PM
Server exception error edray Beginning VB 6 1 July 13th, 2004 09:43 AM
Server Exception Error edray Pro VB 6 0 July 13th, 2004 09:01 AM
Exception Error aadz5 ASP.NET 1.0 and 1.1 Basics 1 November 14th, 2003 10:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.