Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0

    Unhappy I got an error message when using package in Textpad

    I have two classes in same package: class A and class B. B will used an object of class A. Then I compile it. Instead of success, I got error message like this: "package namePackage does not exist"

    Fyi, I placed both A and B in same folder. Therefore, A.class and B.class were in same directory.

    I tried removing package command from both javas and there is no error message. Did anyone ever encounter something like this? Or Textpad couldn't solve problem like this?
    Last edited by magicianseeker; 07-24-2009 at 01:41 PM. Reason: mistype

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,862
    Rep Power
    19

    Default

    Quote Originally Posted by magicianseeker View Post
    I have two classes in same package: class A and class B. B will used an object of class A. Then I compile it. Instead of success, I got error message like this: "package namePackage does not exist"

    Fyi, I placed both A and B in same folder. Therefore, A.class and B.class were in same directory.

    I tried removing package command from both javas and there is no error message. Did anyone ever encounter something like this? Or Textpad couldn't solve problem like this?
    Is that directory called namePackage, and is Textpad (I haven't used it so don't know how it sets up stuff) treating the directory above namePackage as the source directory?

  3. #3
    Join Date
    Jul 2009
    Posts
    2
    Rep Power
    0

    Default

    Yes, the directory (the folder where I put both classes) is namePackage (the name of directory = namePackage).

    Er, how do I know if Textpad treated the directory above namePackage as source directory or not? And why do it need to do so? Can the source (main class) be also in the package?

    Actually, it is like this:
    My current directory now is E:\Java-Source\namePackage. Both of A.class and B.class are in namePackage. Main class is in B.class. So basically I called a class within same package in the same directory. Could it be done?
    Last edited by magicianseeker; 07-27-2009 at 03:57 AM. Reason: add details

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,862
    Rep Power
    19

    Default

    Quote Originally Posted by magicianseeker View Post
    Yes, the directory (the folder where I put both classes) is namePackage (the name of directory = namePackage).

    Er, how do I know if Textpad treated the directory above namePackage as source directory or not? And why do it need to do so? Can the source (main class) be also in the package?

    Actually, it is like this:
    My current directory now is E:\Java-Source\namePackage. Both of A.class and B.class are in namePackage. Main class is in B.class. So basically I called a class within same package in the same directory. Could it be done?
    As I say, I don't know how textpad works, but for compiling you would point java at a source directory, which in your case would be Java-Source. It would then know that classes (.java files) in package namePackage would be found in the directory namePackage.

    Now, if you have textpad (somehow) thinking that namePackage is the source directory then it would give you the error you're getting.

    Other options are that the directory and package names don't match, of course. Ie, there's a typo somewhere.

  5. #5
    adz
    adz is offline Member
    Join Date
    Jul 2009
    Posts
    35
    Rep Power
    0

    Default

    Sounds like you aren't compiling correctly?
    if you had say
    /folder/name/A.java
    /folder/name/B.java
    Java Code:
    package name;
    public class A {
    ...
    }
    
    package name;
    public class B {
    ...
    }
    Then to compile you would go down a directory to "folder" and do
    javac ./name/*.java
    And to run
    java name.A

    Anyway if it works without the packages it means you either didn't put them both in the same folder, didn't put package declarations in both, didn't compile them both correctly or didn't run them correctly.

    Go here for info on packages: java.sun.com/docs/books/tutorial/java/package/packages.html (cant link :/)

  6. #6
    khaze29 is offline Member
    Join Date
    Dec 2010
    Location
    Corona, CA
    Posts
    1
    Rep Power
    0

    Wink TextPad may not support Packages

    Some java tools aren't able to compile classes that have been organized into packages. For example, once you store a Class in (ExampleDirectory.ExampleBusinessPackage) you cant use TextPad to compile the Classes that are in that package because Your Classes depends on some classes that you imported into that class. Try using the command prompt to compile your classes in the package. To do that>>>>>.. here are the steps.

    1. Open your command prompt in windows.
    2. once youre in the command prompt. go to the root directory of your packages.
    3. here is the syntax: Ex:

    C:\java\ lineItem>javac king/business/LineItem.java
    //notice: this is just an example, it depends on you where you saved your package.

    this is what you call the"javac command".

    if Im wrong, please give me some more info. I'd like to be schooled.
    String p = "peace";
    String o = "Out";
    System.out.println( "Hope this solves your problem \n" +p+o);

Similar Threads

  1. Same error msg with every program Java Textpad
    By peterdfl in forum New To Java
    Replies: 7
    Last Post: 04-17-2009, 04:49 AM
  2. Compiles in Netbeans, error in textpad
    By Npcomplete in forum New To Java
    Replies: 2
    Last Post: 11-21-2008, 04:50 AM
  3. Error Message in JBuilder
    By RavenNevarmore in forum New To Java
    Replies: 4
    Last Post: 10-08-2008, 06:53 AM
  4. strange Error message
    By little_polarbear in forum New To Java
    Replies: 4
    Last Post: 08-25-2008, 11:45 PM
  5. error message on jsp
    By sandor in forum Web Frameworks
    Replies: 1
    Last Post: 04-11-2007, 02:10 AM

Tags for this Thread

Posting Permissions

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