Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems with compiling class packages

0 views
Skip to first unread message

Tony Lawrie

unread,
Aug 30, 2002, 2:46:37 PM8/30/02
to
Hi,

Can anyone give me some advice on how I can get two package classes to
compile with Linux (Suse 7.3). I'm just on learning java and have two
classes "Dice" and "ThrowDice" to learn to use packages in java as a test.
Dice is stored in subdirectory home/antlaw/java/Applications/Parsons and
ThrowDice is stored in home/antlaw/java/Applications/ .

In Dice I use "package Application.Parsons" and in ThrowDice I use "package
Applications". In my home profile file i've got the following classpath
setting

export JAVA_HOME=PATH=/home/antlaw/java:$PATH

Dice compiles fine, but when I go to compile Throwdice I get the following
error report

ThrowDice.java:7: cannot resolve symbol
symbol : class Dice
location: class Applications.ThrowDice
Dice dice1 = new Dice();
^
ThrowDice.java:7: cannot resolve symbol
symbol : class Dice
location: class Applications.ThrowDice
Dice dice1 = new Dice();
^
ThrowDice.java:8: cannot resolve symbol
symbol : class Dice
location: class Applications.ThrowDice
Dice dice2 = new Dice();
^
ThrowDice.java:8: cannot resolve symbol
symbol : class Dice
location: class Applications.ThrowDice
Dice dice2 = new Dice();
^
4 errors
antlaw@linux:~/java/Applications>

I've tried various variations including importing Application.Parsons.Dice
into ThrowDice Class as an additional line after the package line but I
still get error resports under compilation. If I put both classes into the
same subfolder they compile okay - but I was wanting to understand what I'm
doing wrong with packages or if my classpath isn't correctly set up.
Any help will be gratefully received - Cheers -- Tony.
--
Linux user : tonl@ freenet.co.uk

Tony Lawrie

unread,
Aug 30, 2002, 7:40:12 PM8/30/02
to
Tony Lawrie wrote:

I've managed to get it working. What I had to do was declare "package
Parsons" for Dice class, and "import Parsons.Dice" in ThrowDice class. I
also changed the class path in home profile to

export PATH=/home/antlaw/java:$PATH

There still isn't something I understand though. In the book I'm working
through it stated to declare the "uses" class (ThrowDice) as a package
also. In this case "package Applications" but if I put this in it compiles
okay but when I go to run it I get a load of exceptions being thrown as
follows:

Exception in thread "main" java.lang.NoClassDefFoundError: ThrowDice (wrong
name: Applications/ThrowDice)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)

Has anyone any ideas why this happens?

Cheers -- Tony.

0 new messages