PDA

View Full Version : problem with a package...


inkedmn
11-24-2002, 11:32 PM
i'm redesigning/rewriting joana (my irc bot), and i'm trying to utilize java's package system. i'm having a problem...

each source file has "package joana;" at the top, as per the docs i read. so, i wrote this little test class for the Irc object (handles the connection, etc):


package joana;

public class Joana {
Irc irc = new Irc("irc.oftc.net");
irc.die();
}


now, bear in mind that that is a valid constructor and the die() method does exist (and the Irc class is in the joana package)

when i try to compile this code, these are the errors i get:


D:\development\java_practice\joana>javac Joana.java
Joana.java:5: <identifier> expected
irc.die();
^
Joana.java:5: package irc does not exist
irc.die();
^
2 errors


any idears?

jemfinch
11-25-2002, 02:19 AM
I have no idea about your package problem, but note that you should be able to set a port in the constructor on your Irc object.

Jeremy

inkedmn
11-25-2002, 10:05 AM
yeah, i've been thinking about that, i'll probably write another constructor that takes two args, but the default irc port is already specified in JoanaConf :)

[edit]

I'M A RETARD...

maybe the Joana class needs a FREAKING MAIN METHOD!!!

bah...

Dru Lee Parsec
11-25-2002, 12:42 PM
Is the Irc class also in the Joanna package?

inkedmn
11-25-2002, 12:44 PM
yes

Dru Lee Parsec
11-25-2002, 02:15 PM
Hmmm. Then the Joanna class should be able to access the Irc class. When I've run into these kinds of problems it's usually been one of these issues:

1. I forgot to put the package declaration in one of the classes.
2. There's an old .class file in the class path that isn't in the proper package.
3. The class path is pointed to the wrong direcory. I'll explain further:

I put my source code in a directory called "src". I make my code compile to a directory called "lib". The lib directory is in my classpath.

Assuming a similar set up there would be a directory under src called joanna. All files in the joanna package would be in the src/joanna directory. If your javac destination is the lib directory then when you compile them it will create a lib/joanna directory with class files created by compiling the src/joanna directory.

So far so good?

Some people make the mistake of thinking they need to put the lib/joanna directory in their classpath. You only need to put the lib directory in your classpath. The JVM is smart enough to append the package name to the path name to find the class file. So, if you have a class called MyClass in a package called com.inkedmn.gui and your lib directory is in the classpath then the JVM will automatically look for Myclass.class in
lib/com/inkedmn/gui

I don't know if any of that helps but it might be a place to start looking. I don't think adding a main method will fix the compile problem. It sure sounds like some variation of a classpath problem.

Hope it helps.

inkedmn
11-25-2002, 02:24 PM
excellent, i'll try it when i get home...

thanks Dru!

inkedmn
11-26-2002, 10:47 AM
update:

it was my classpath. i brought the code to work and now it compiles fine :)

thanks again duders