Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
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 April 7th, 2008, 05:25 PM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default UnsupportedClassVersionError

Hi!

I'm a java newbie and I'm learning from the book Beginning Java 2

I have the following code from the book stored and it works from the jdk\bin directory but when I compile and attempt to execute it in a new directory I get the exception in the subject above.

Code:

class Sphere
{
    static final double PI = 3.14; // Class variable that has a fixed value
    static int count = 0; // Class variable to count objects

    // Instance Variables
    double radius; // radius of a sphere

    double xCenter;
    double yCenter;
    double zCenter;

    // Class constructor
    Sphere(double theRadius, double x, double y, double z)
    {
        radius = theRadius;

        // Set the coordinates of the center
        xCenter = x;
        yCenter = y;
        zCenter = z;
        ++count;
    }

    // Static method to report the number of objects created
    static int getCount()
    {
        return count;
    }

    // Instance method to calculate volume
    double volume()
    {
        return 4.0/3.0*PI*radius*radius*radius;
    }

}

class CreateSpheres
{
    public static void main(String[] args)
    {
        System.out.println("Number of objects = " + Sphere.getCount());

        Sphere ball = new Sphere(4.0,0.0,0.0,0.0); // Create a sphere
        System.out.println("Number of objects = " + ball.getCount());

        Sphere globe = new Sphere(12.0,1.0,1.0,1.0); // Create a sphere
        System.out.println("Number of objects = " + Sphere.getCount());

        // Output the volume of each sphere
        System.out.println("ball volume = " + ball.volume());
        System.out.println("globe volume = " + globe.volume());
    }

}


in the system path I have the following

;C:\Program Files\Java\jdk1.6.0_03\bin;C:\Program Files\Java\jdk1.6.0_03\jre

any help with this is appreciated.

Thanks,

T
 
Old April 8th, 2008, 03:01 AM
jomet
Guest
 
Posts: n/a
Default

add another entry for class path in environment variables.
My C0mputer-> properties ->advanced tab->environment variables->user variables
->New
Enter
Name: CLASSPATH
value: .;


jomet.
---------------------------------------------
Once you start a working on something,
dont be afraid of failure and dont abandon it.
People who work sincerely are the happiest.
 
Old April 8th, 2008, 10:26 AM
Registered User
 
Join Date: Apr 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

jomet,

Thank you sincerely for taking time to help me.

I now have the following value in an environment variable CLASSPATH.

C:\Program Files\Java\jdk1.6.0_03\bin;C:\Program Files\Java\jdk1.6.0_03\jre;C:\Java\CreateSpheres

I still get the same exception while executing.

T









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