Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-21-2003, 12:39 AM   PM User | #1
Roost3r
New Coder

 
Join Date: Aug 2002
Location: PA
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Roost3r is an unknown quantity at this point
Java Compile/Run Problem

Hi,
I'm new to working with java; for my class lab assignment I had to copy files from one directory and put them in my /Java/Lab4/inventory/ directory.... i can compile my Inventory.java file by typing

javac -classpath $HOME/Java/Lab4 Inventory.java

that then creates Inventory.class file in that same directory... and i want to run it; thats where the problem is; to run it im typing

java -classpath $HOME/Java/Lab4 Inventory.class
I've also tried
java Inventory.class

The error I'm getting is

Exception in thread "main" java.lang.NoClassDefFoundError: /users/klepeis/Java/Lab4

any help would be greatly appreciated
Roost3r is offline   Reply With Quote
Old 03-21-2003, 12:57 AM   PM User | #2
Jason
Regular Coder

 
Join Date: Feb 2003
Location: California
Posts: 925
Thanks: 0
Thanked 0 Times in 0 Posts
Jason is an unknown quantity at this point
that says there is an error in the main of that file. At least thats how its read if it were C/C++ but you might try just Inventory.class, is there an object file to run otherwise?


Jason
Jason is offline   Reply With Quote
Old 03-21-2003, 01:02 AM   PM User | #3
Roost3r
New Coder

 
Join Date: Aug 2002
Location: PA
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Roost3r is an unknown quantity at this point
it compiles fine it just gives that error when i try to run it... there is no main in inventory; it is part of a package (called inventory)

... do you mean at the console try running it by typing just "Inventory.class" ?

the only files in the directory where my package is are .java and .class
Roost3r is offline   Reply With Quote
Old 03-21-2003, 01:03 AM   PM User | #4
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,234
Thanks: 4
Thanked 81 Times in 80 Posts
Spookster will become famous soon enough
You can use spaces in your file name:

Lab4 Inventory.java

if Lab4 is a directory then make sure you put a slash there. Also your filename must match the class name of your main method(to include capitalization. In other words if you are compiliing:

javac Inventory.java

then you should have a class defined in your file like so:

class Inventory{

public static void main(String[] bean){

}//end main

}//end Inventory
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 03-21-2003, 01:04 AM   PM User | #5
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,234
Thanks: 4
Thanked 81 Times in 80 Posts
Spookster will become famous soon enough
Quote:
Originally posted by Roost3r
it compiles fine it just gives that error when i try to run it... there is no main in inventory; it is part of a package (called inventory)

... do you mean at the console try running it by typing just "Inventory.class" ?

the only files in the directory where my package is are .java and .class
oh ok. Then have your properly declared it as a package in your files?
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 03-21-2003, 01:18 AM   PM User | #6
Roost3r
New Coder

 
Join Date: Aug 2002
Location: PA
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Roost3r is an unknown quantity at this point
ive done it again compiling my file by typing:
javac -classpath $HOME/Java/Lab4/ InventoryTest.java
it creates InventoryTest.class
to run it i tried:
java -classpath $HOME/Java/Lab4/ InventoryTest.class and
java InventoryTest.class

error when trying to run:
Exception in thread "main" java.lang.NoClassDefFoundError: InventoryTest/class

why would it compile with no error then get a error on running...
I looked in the InventoryTest.java file and the main function looks fine...

since this is part of a package do i maybe need to do something liek this?
java InventoryTest.class Inventory.class ... (with all the classes of the inventory?)
Roost3r is offline   Reply With Quote
Old 03-21-2003, 01:19 AM   PM User | #7
Roost3r
New Coder

 
Join Date: Aug 2002
Location: PA
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Roost3r is an unknown quantity at this point
package inventory; is at the top of each package file and the directory it is in is called "inventory" (/Java/Lab4/inventory/)

files in the package are:
RevisedInventoryTest.java
RetailItemDB.java
InventoryTest.java
Inventory.java
DBTest.java

and 2 classes are used in some of these files
RetailItem.class
RetailItemList.class

Last edited by Roost3r; 03-21-2003 at 01:24 AM..
Roost3r is offline   Reply With Quote
Old 03-21-2003, 02:28 AM   PM User | #8
Spookster
Supreme Overlord


 
Spookster's Avatar
 
Join Date: May 2002
Location: Marion, IA USA
Posts: 6,234
Thanks: 4
Thanked 81 Times in 80 Posts
Spookster will become famous soon enough
In your main class if you are trying to import any of those files from the package you need to make sure those package files are already compiled. From your main directory compile those package file like so:

javac -classpath $HOME/Java/Lab4/inventory/RevisedInventoryTest.java

and do that for the rest of them. You might be able to do them all at once like:

javac -classpath $HOME/Java/Lab4/inventory/*.java

Then compile your main class file.
__________________
Spookster
CodingForums Supreme Overlord
All Hail Spookster
Who gave you that Ugging infraction? Yeah that's right it was me!
Spookster is offline   Reply With Quote
Old 03-21-2003, 02:38 AM   PM User | #9
Roost3r
New Coder

 
Join Date: Aug 2002
Location: PA
Posts: 93
Thanks: 0
Thanked 0 Times in 0 Posts
Roost3r is an unknown quantity at this point
ok ill try that , thanks alot
Roost3r is offline   Reply With Quote
Old 03-21-2003, 05:47 AM   PM User | #10
psp
New Coder

 
Join Date: Mar 2003
Location: CA
Posts: 18
Thanks: 1
Thanked 0 Times in 0 Posts
psp is an unknown quantity at this point
You don't have to give any extension to the file name when you are running it.
That is if you have a program called Inventory.java ,after u compile it , a class file is generated Inventory.class.
When u run it, just the command would be
java Inventory
NOT java Inventory.class
No extension is required.(.class)
See if this was the problem.
psp is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:24 PM.


Advertisement
Log in to turn off these ads.