Results 1 to 7 of 7
  1. #1
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default problem - using a jar file

    Using Netbeans 6.0 I've:

    1. Created a new Java application named CalculatorTest
    2. Imported Calculator.jar within the projects, under the Libraries.

    Within the library there are two class files named:
    MyCanvas.class
    SysCalculator.class

    I tried to instantiate the SysCalculator, unsuccessfully. Anyone encountered similar problems?
    :confused:

    <code>
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package calculatortest;

    /**
    *
    * @author Administrator
    */
    //import ??
    public class Main {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    SysCalculator myCalc = new SysCalculator(); //Error

    }

    }

    </code>

    Compile error:
    symbol : class SysCalculator
    location: class calculatortest.Main
    SysCalculator myCalc = new SysCalculator();
    C:\Documents and Settings\Administrator.SERVER02\My Documents\NetBeansProjects\CalculatorTest\src\calc ulatortest\Main.java:19: cannot find symbol
    symbol : class SysCalculator
    location: class calculatortest.Main
    SysCalculator myCalc = new SysCalculator();
    2 errors
    BUILD FAILED (total time: 0 seconds)

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    Somewhere in Netbeans you need to specify the name of the jar file(s) containing the missing class so that it can be added to the classpath for the javac command.
    Sorry I don't use Netbeans.

  3. #3
    jon80's Avatar
    jon80 is offline Senior Member
    Join Date
    Feb 2008
    Location
    Malta (EU)
    Posts
    211
    Rep Power
    7

    Default

    I have Eclipse as well, any idea how to do that? Any other IDEs?

    I just need to get it working :-)

  4. #4
    Jeremy is offline Member
    Join Date
    Jul 2008
    Posts
    28
    Rep Power
    0

    Default

    It might help to see what your import statement was.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,883
    Rep Power
    25

    Default

    My IDE is very simple and makes me configure my commandlines, for compiling and for testing and to set the starting directory.

    For compiling the commandline would be something like:
    javac -classpath <jarfiles> <java source name>

    For example:
    javac -classpath .;jarfile1.jar;jarfile2.jar MyProgram.java

    As Jeremy mentions, is the missing program in a package?
    This would require you to have an import statement in your program specifing that package.
    The compiler MUST find the definitions for ALL the classes you reference in your program. The compiler will use the classpath to find missing classes other that the ones belonging to java itself. The total path to the class will consist of the classpath + the package path. For example say MyClass is located on this path: D:\work\my\pack1\MyClass.class and MyClass was in package pack1.
    For the compiler to find this class it would need a classpath of: D:\work\my
    The my folder contains a sub folder pack1 with the MyClass.class file.

    Bottom line. Check if you need an import statement for the package that the missing class is in.
    Last edited by Norm; 07-07-2008 at 12:34 AM.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by jon80 View Post
    Using Netbeans 6.0 I've:

    1. Created a new Java application named CalculatorTest
    2. Imported Calculator.jar within the projects, under the Libraries.

    Within the library there are two class files named:
    MyCanvas.class
    SysCalculator.class

    I tried to instantiate the SysCalculator, unsuccessfully. Anyone encountered similar problems?
    :confused:

    <code>
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    package calculatortest;

    /**
    *
    * @author Administrator
    */
    //import ??
    public class Main {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    SysCalculator myCalc = new SysCalculator(); //Error

    }

    }

    </code>

    Compile error:
    symbol : class SysCalculator
    location: class calculatortest.Main
    SysCalculator myCalc = new SysCalculator();
    C:\Documents and Settings\Administrator.SERVER02\My Documents\NetBeansProjects\CalculatorTest\src\calc ulatortest\Main.java:19: cannot find symbol
    symbol : class SysCalculator
    location: class calculatortest.Main
    SysCalculator myCalc = new SysCalculator();
    2 errors
    BUILD FAILED (total time: 0 seconds)
    Did you import the package(or the specific Java class) in to your application?

  7. #7
    Eku
    Eku is offline Senior Member
    Join Date
    May 2008
    Location
    Makati, Philippines
    Posts
    234
    Rep Power
    7

    Default

    you can import each of their packages if they are in their own respective packages and implements or extend them in your Main Class.
    Mind only knows what lies near the heart, it alone sees the depth of the soul.

Similar Threads

  1. Problem in file implementation
    By BHCluster in forum New To Java
    Replies: 6
    Last Post: 04-21-2008, 04:21 AM
  2. problem with jar file pls help
    By jinu5 in forum New To Java
    Replies: 0
    Last Post: 08-15-2007, 11:41 PM
  3. Problem in batch file
    By marwa in forum New To Java
    Replies: 0
    Last Post: 08-14-2007, 11:24 AM
  4. Problem in opening a file
    By Raghav kv in forum New To Java
    Replies: 1
    Last Post: 08-11-2007, 02:55 PM
  5. problem when I try to delete a file
    By tommy in forum Advanced Java
    Replies: 2
    Last Post: 07-31-2007, 03:44 PM

Posting Permissions

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