Jump to content

Trouble with Packages

- - - - -

  • Please log in to reply
8 replies to this topic

#1
Chroferus

Chroferus

    Newbie

  • Members
  • Pip
  • 5 posts
I've been studying Java using the tutorial on Sun's website. As I've been going along, I've been adding what I learn to a game prototype. I recently reached the packages chapter and attempted packaging my game. However, after packaging, my files couldn't find each other. I spent a while trying to fix it, and then made a simple package with the following two files:

C:\Users\Kenny\Desktop\testpackage\TestSuperClass.java:

package testpackage;

public class TestSuperClass {


}

C:\Users\Kenny\Desktop\testpackage\TestSubClass.java:

package testpackage;

public class TestSubClass extends TestSuperClass {


}

I can compile TestSuperClass.java, but when I try to compile TestSubClass.java, I get the following error:

TestSubClass.java:2: cannot find symbol

symbol: class TestSuperClass

public class TestSubClass extends TestSuperClass {

                                  ^

My classpath is set with the following line:

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

Can anyone explain to me what I'm doing wrong?

#2
Xylyze

Xylyze

    Newbie

  • Members
  • Pip
  • 8 posts
Which IDE are you using?

#3
Chroferus

Chroferus

    Newbie

  • Members
  • Pip
  • 5 posts
I'm using the 1.6.0_23 version of the JDK.

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
With IDE he/she meant your code editor like eclips, netbeans,...

#5
Chroferus

Chroferus

    Newbie

  • Members
  • Pip
  • 5 posts
I'm not entirely sure I'm even using an IDE. I'm just using Notepad2 to write my Java files and the javac application included in the JDK I installed to compile.

#6
mnirahd

mnirahd

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 330 posts
Hi,

I would like to suggest you to use IDE like eclipse/Jbuilder.

I think your problem is that you have to create a folder having same name as packet name: and put your source/class files in it.

if you use IDE like Jbuilder: it would make your life easier as it should take care of such things itself.

Munir

#7
Chroferus

Chroferus

    Newbie

  • Members
  • Pip
  • 5 posts
I'm sure it's in a folder to match the package.

Chroferus said:


C:\Users\Kenny\Desktop\testpackage\TestSuperClass.java:

[B]package testpackage[/B];

public class TestSuperClass {


}

As for the IDE, I might end up trying one, but I really want to understand this error.

#8
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
In some cases it is important that the user learn how to write code with a simple editor like notepad or notepad2.

It allows the new programmer to write their code and learn more about the architecture of programming/compiling/executing/finding errors/classpaths/packages/etc.

To the OP. If you decide NOT to use an IDE I'd recommend doing a google search about how to use packages and set up classpaths.
You are obviously missing a minor detail somewhere in your classpath. You just have to find what that problem is. And that will make you a stronger user.

I came across this with on google:
Java Package Tutorial (English version)

There are many more tutorials out there if this doesn't help you.

#9
Chroferus

Chroferus

    Newbie

  • Members
  • Pip
  • 5 posts
Thanks. I visited the site and looked how they set the classpath. I copied my file to C:\, changed to the directory, copied the command into my command prompt, and it compiled. The funny part is, I had already looked at that site. But I didn't try setting the classpath the same exact way they did. You were right, there was one small detail I missed.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users