-
java.lang.NoClassDefFoundError
Having problems with my assignment for college. Newbie and new to this forum so bare with me.
Been asked to do the following:
"Write a class called, Product that has the following attributes a name, a price and description. Write get and set methods for each of the attributes. It should have a constructor that takes three parameters, name, price and description. It should also have a toString method that returns the details of the Product.A stock room can hold a fixed number of Products, e.g. fixed number is 10 then the maximum number of products a stock room can hold is 10.
Create a class called, StockRoom that will store the fixed number of Products (hint: array). The StockRoom will have a constructor that takes an integer, which represents the fixed number (or maximum number) of Products that the stock room can hold.
This class should include methods to allow for
- new products to be added to the stock room – cannot store more than maximum number allowed in the stock room.
- a list of all products to be printed out.
Write an application to test the methods of the StockRoom."
This is what I have at the moment.
-----------------------------------------------------------------------
public class Product{
public String name;
public Double price;
public String description;
public String productString;
public Product(){
}
public Product(String name, Double price, String description){
this.name=name;
this.price=price;
this.description=description;
}
public String toString(){
productString="name" + "price" + "description";
return productString;
}
public void setName(String name){
this.name=name;
}
public void setPrice(Double price){
this.price=price;
}
public void setDescription(String description){
this.description=description;
}
public String getName(){
return name;
}
public Double getPrice(){
return price;
}
public String geDescription(){
return description;
}
}
------------------------------------------------------------------------
public class StockRoom{
public Product[] stockRoomArray;
public int maxPoductsInStockRoom;
public int productPosition;
public Product productToAdd;
public StockRoom(int maxPoductsInStockRoom){
this.maxPoductsInStockRoom=maxPoductsInStockRoom;
stockRoomArray = new Product[maxPoductsInStockRoom];
}
public void printProductList(){
int n;
for (n=0;n<maxPoductsInStockRoom;n++){
System.out.println("Product in position "+n+": "+stockRoomArray[n]);
}
}
public int addProduct(Product productToAdd){
if (productPosition>=maxPoductsInStockRoom){
System.out.println("The stock room is full!");
}
else{
stockRoomArray[productPosition]= productToAdd;
}
return productPosition;
}
public void addPos(int productPosition, Product productToAdd){
stockRoomArray[productPosition]= productToAdd;
}
}
-----------------------------------------------------------------------
When I run StockRoom I get java.lang.NoClassDefFoundError: StockRoom
Both compiles without errors. Any idea whats wrong with the code? Any help is much appreciated.
Email
Last edited by corleone; 11-24-2006 at 05:42 AM.
-
There is nothing wrong with your code if it compiles correctly. Occaisonally, Java gives this error. I have suffered the same error on various occaisions; usually it's because of the way you're trying to run the .class file.
I know of no fix that works in every case, and can't offer any suggestions without knowing how you're trying to run StockRoom.class.
-
How exactly did you plan on running a class with no main method? That error is being thrown because you're trying to run a class with no main method.
Code:
public static void main(String[] args)
-
Try adding current directory (./) in your classpath and run.
Similar Threads
-
Replies: 7
Last Post: 04-02-2007, 05:35 PM
-
Replies: 2
Last Post: 12-05-2005, 05:27 PM
-
Replies: 8
Last Post: 10-20-2005, 06:42 AM
-
Replies: 2
Last Post: 05-25-2005, 01:24 AM
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks