Some trouble with packages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lucas McCarthy
    New Member
    • Dec 2010
    • 5

    Some trouble with packages

    I've started studying java using the tutorial on Oracle. I've been making a program as I've gone along in the tutorial, adding what I learn to the program. When I reached the packages section, I tried packaging my program. However, after I set up the package, my files couldn't find each other. After a couple frustrating hours of trying to fix it, I made a simple package with the following files:

    C:\Users\Kenny\ Desktop\testpac kage\TestSuperC lass.java:

    Code:
    package testpackage;
    public class TestSuperClass {
    
    }
    C:\Users\Kenny\ Desktop\testpac kage\TestSubCla ss.java (ignore the space)

    Code:
    package testpackage;
    public class TestSubClass extends TestSuperClass {
    
    }
    I can compile TestSuperClass. java, but when I compile TestSubClass.ja va, I get the following error:

    Code:
    TestSubClass.java:2: cannot find symbol
    symbol: class TestSuperClass
    public class TestSubClass extends TestSuperClass {
                                      ^
    I've set up the appropriate folders for the package and set the directory to my classpath. I've been trying to figure this out all day. Can someone explain to me what I'm doing wrong?
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    My test program compiles properly. Are you sure all the class paths are correct?

    Regards
    Dheeraj Joshi

    Comment

    • Lucas McCarthy
      New Member
      • Dec 2010
      • 5

      #3
      I should think so. I unset the classpath then set it to the folder.

      Code:
      set CLASSPATH=
      set CLASSPATH=C:\Users\Kenny\Desktop\testpackage

      Comment

      • Dheeraj Joshi
        Recognized Expert Top Contributor
        • Jul 2009
        • 1129

        #4
        Try compiling your main method with -cp option from command line and check.

        Regards
        Dheeraj Joshi

        Comment

        • Lucas McCarthy
          New Member
          • Dec 2010
          • 5

          #5
          I'm not entirely sure what you mean. Sorry, Java is a bit difficult for me to understand.

          Comment

          • Dheeraj Joshi
            Recognized Expert Top Contributor
            • Jul 2009
            • 1129

            #6
            Check this link.

            Regards
            Dheeraj Joshi

            Comment

            • Lucas McCarthy
              New Member
              • Dec 2010
              • 5

              #7
              I entered the following line:
              Code:
              C:\Java\jdk\bin\javac -classpath C:\Users\Kenny\Desktop\testpackage TestSubClass.java
              and got the same error. Do you think it might be to do with my Java installation?

              Comment

              Working...