|
-
Jul 27th, 2000, 02:41 PM
#1
Thread Starter
New Member
class help
Hi,
I'm working on a class architecture for a shopping system. I'm working with Java JDK 1.1.8 of a windows console. And I'm having a problem with linking my two classes together. Any help would be great.
PS. I know this is a easy prob. Sorry I'm a newbie to java
The error I recieve is :
Code:
C:\jdk1.1.8\bin>javac Book.java
Book.java:3: Superclass Orderable.Orderable of class Orderable.Book not found.
public class Book extends Orderable
^
1 error
----------------------------------------------------------
The two classes I'm working with are
Orderable.java -------
Code:
package Orderable;
public abstract class Orderable
{
public int itemNumber, itemQuantity;
public String itemName;
public double itemPrice;
public Orderable(int anItemNumber, String anItemName, double anItemPrice, int anItemQuantity)
{
this.itemNumber = anItemNumber;
this.itemName = anItemName;
this.itemPrice = anItemPrice;
this.itemQuantity = anItemQuantity;
}
public Orderable()
{
this.itemNumber = 0;
this.itemName = null;
this.itemPrice = 0;
this.itemQuantity = 1;
}
public int getItemNumber() { return itemNumber; }
public void setItemNumber ( int anItemNumber )
{
this.itemNumber = anItemNumber;
}
public String getItemName() { return itemName; }
public void setItemName ( String anItemName )
{
this.itemName = anItemName;
}
public double getItemPrice() { return itemPrice; }
public void setItemPrice( double anItemPrice )
{
this.itemPrice = anItemPrice;
}
public int itemQuantity() { return itemQuantity; }
public void setItemQuantity ( int anItemQuantity )
{
this.itemQuantity = anItemQuantity;
}
public boolean isLessThan(Orderable anOrderable)
{
return true;
}
public abstract void print();
}
Book.java -----------
Code:
package Orderable;
public class Book extends Orderable
{
protected String author;
protected int edition;
public Book(int anItemNumber, String anItemName, double anItemPrice, int anItemQuantity, String anAuthor, int anEdition)
{
super(anItemNumber, anItemName, anItemPrice, anItemQuantity);
this.author = anAuthor;
this.edition = anEdition;
}
public Book()
{
super();
this.author = null;
this.edition = 0;
}
public String getAuthor() {return author;}
public void setAuthor (String anAuther)
{
this.author = anAuthor;
}
public int getEdition() {return edition;}
public void setEdition (String anEdition)
{
this.edition = anEdition;
}
public void print()
{
System.out.println("Item Number: "+super.itemNumber);
System.out.println("Item Name: "+super.itemName);
System.out.println("Item Price: "+super.itemPrice);
System.out.println("Item Quantity: "+super.itemQuantity);
System.out.println("Author: "+author);
System.out.println("Edition: "+edition);
}
}
[Edited by knlu on 07-31-2000 at 01:20 PM]
-
Jul 30th, 2000, 03:12 PM
#2
Monday Morning Lunatic
Make sure that Orderable is compiled and in the classpath BEFORE you try and compile Book.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 31st, 2000, 07:13 AM
#3
Frenzied Member
And use code tags, makes things easier to read. There's a link at the top of this page to see how to use code tags - where it says 'vB code is ON'.
Harry.
"From one thing, know ten thousand things."
-
Jul 31st, 2000, 12:24 PM
#4
Thread Starter
New Member
Thank you for your replies. But I think that my problem extends from my packaging techniques. I have all the .java files in the same directory and yes i did compile Orderable first. It compiled fine. I still recieve the same error. Thank you for your help. But i still need some more. Any extra help would be great.
-
Jul 31st, 2000, 12:35 PM
#5
Monday Morning Lunatic
The Java package system works this way: You must have packages corresponding to folders. As in:
CLASSPATH = C:\Java\Classes
C:\Java\Classes\uk\co\katisha\Orderable.java is in package uk.co.katisha
If there is not a folder to correspond to the package, it will die.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 6th, 2000, 01:38 PM
#6
Dazed Member
Hey parksie im having trouble to and if anyone on this post can help it would probably be you. If i have another class called Rectangle in another file how do i compile SomethingIsWrong so it can link to or whatever it does to
Rectangle. I keep getting Package doesnot exist compile time errors.
import java.Rectangle.*; // This doesnt seem to work
public class SomethingIsWrong {
public static void main(String[] args) {
Rectangle myRect = new Rectangle();
myRect.width = 40;
myRect.height = 50;
System.out.println("myRect's area is " + myRect.area());
}
}
thanks................
-
Nov 6th, 2000, 01:41 PM
#7
Monday Morning Lunatic
If you don't specify a package anywhere, then they go into the local package, which is basically the current folder. So, if Rectangle.java does not define a package, you don't need to import it into SomethingIsWrong as long as they're in the same folder.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 6th, 2000, 01:53 PM
#8
Dazed Member
This is the code i have, but it keeps generating compile time errors.If i take out import java.Rectangle.*; and
package Rectangle; I get cannot resolve symbol
Rectangle myRect = new Rectangle();
^
If i leave them in like i have here Rectangle compiles fine
but SomethingIsWrong generates package Rectangle doesnot exist import Rectangle.*;
^
import Rectangle.*;
public class SomethingIsWrong {
public static void main(String[] args) {
Rectangle myRect = new Rectangle();
myRect.width = 40;
myRect.height = 50;
System.out.println("myRect's area is " + myRect.area());
}
}
//Then this class is in another file call Rectangle
package Rectangle;
public class Rectangle {
public int width = 0;
public int height = 0;
// a method for computing the area of the rectangle
public int area() {
return width * height;
}
}
-
Nov 6th, 2000, 01:57 PM
#9
Monday Morning Lunatic
If it's in package Rectangle, then it would need to be under a folder:
%CLASSPATH%\Rectangle\Rectangle.class
Confusing, I know, but once you've got it sussed there's no problem.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 6th, 2000, 02:04 PM
#10
Dazed Member
Ahhhhhhhhhh ok. I got it. I always want to say thanks but i dont want people to think i like to get my post count up by posting thanks all of the time....... {{{laughing}}} But thanks!! anyway.
-
Nov 6th, 2000, 03:51 PM
#11
Monday Morning Lunatic
King of the useless posters returns...
It's always nice to get a thankyou, as has been shown with the many threads started by people saying how nice it was.
Anyway, for more info on packages, http://www.java.sun.com has lots of info.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|