Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Aug 2002
    Location
    PA
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #3
    New Coder
    Join Date
    Aug 2002
    Location
    PA
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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

  • #5
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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

  • #6
    New Coder
    Join Date
    Aug 2002
    Location
    PA
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?)

  • #7
    New Coder
    Join Date
    Aug 2002
    Location
    PA
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,278
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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

  • #9
    New Coder
    Join Date
    Aug 2002
    Location
    PA
    Posts
    93
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok ill try that , thanks alot

  • #10
    psp
    psp is offline
    New Coder
    Join Date
    Mar 2003
    Location
    CA
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •