Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

packages

Status
Not open for further replies.

Kyuss

Programmer
Feb 21, 2001
15
AU
hey there, i dont do much java and you will be able to see why now

say if have a package com.me

i have two classes in this package myUtils and myFun

they have a number of methods and these work fine if i call them from a jsp individually, however when i want to call a method from myUtils whithin myFun and compile, i get an unresolved symbol.

eg:
package com.my
public class myUtils {

public void myUtils() {}
public void aMethod(){}
}

package com.my
public class myFun {

myUtils blah = new myUtils();
blah.aMethod();
}

have i compiled them correctly or is there something else i am not doing properly?

thanks for any help!
and the circus leaves town...
 
1) Sounds like a CLASSPATH issue. Make sure that the com.my package is on your SYSTEM CLASSPATH. So if the com directory is located in a classes directory you need to put that classes directory on the CLASSPATH.

2) One minor note on myUtils.

Incorrect:
package com.my
public class myUtils {

/* Not a Constructor because of void */
public void myUtils() {}

public void aMethod(){}
}

Correct:
package com.my
public class myUtils {

public myUtils() {}
public void aMethod(){}
}

3) Major problem in myFun.
Incorrect:
package com.my
public class myFun {
/* These need to be in a method */
myUtils blah = new myUtils();
blah.aMethod();

}

Correct:
package com.my
public class myFun {

public static void main(String args[]) {
myUtils blah = new myUtils();
blah.aMethod();
}

}
Wushutwist
 
Thanks mate!

yeah, i just wrote those quickly as an example, sorry, very sloppy.

you were right though, was a problem with my compilation method, i found that it sorted itself out when i compiled all the class files together...maybe that is what i was meant to be doing from the start, and would have saved me a couple of hours of frustration =) and the circus leaves town...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top