aspose file tools*
The moose likes Beginning Java and the fly likes Import problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Import problems" Watch "Import problems" New topic
Author

Import problems

Cheryl Gray
Ranch Hand

Joined: Nov 17, 2000
Posts: 44
What am I doing wrong?
I am using Jbuilder and I would like to import arrlst.java from another package into my current class.
My current package is testaccess.
My imported class lies in chp5 package.
I used import chp5.arrlst; or import chp5.*;
This is my code:
package testaccess;
import chp5.*;
public class myaccess extends arrlst
{
public static void main(String[] args) {
myaccess myaccess1 = new myaccess();
arrlst ar3 = new arrlst();
ar3.method1(); //method1 is protected
}
}
Am I missing something


Anything is possible to those who believe.
Matthew Vincent
Greenhorn

Joined: May 01, 2003
Posts: 8
Hi Cheryl!
I'm not sure if this will help you or not, but I'll take a shot.
Let's say you are trying to compile from cthe directory c:\java. Your directory structure should look like the following:

With this setup and your class path set to just your local directory (in this case c:\java or .), you should just be able to compile with:

Alternatively, you could have the chp5 directory anywhere on your system as long as your classpath variable knows where it is. For example, if your chp5 directory was located at d:\mylibs\chp5, you could compile with:

I hope that helps you!
Matt
[ May 01, 2003: Message edited by: Matthew Vincent ]
Cheryl Gray
Ranch Hand

Joined: Nov 17, 2000
Posts: 44
Hi Matt:
Actually, it's the other way around.
chp5 is pkg1
-has arrlst.java
testaccess is pkg2
- has class myaccess which subclasses arrlst.java and accesses protected method1() in this class
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Possibly just adding the arrlst.java file to your project will solve the problem. More likely, you need to add the directory that contains chp5 to the CLASSPATH. I haven't used JBuilder, so I don't know if it provides a convenient way to set the classpath. However, you can change it manually, but this differs slightly between Win9x/ME and WinNT/2K/XP. I suggest you first look in the JBuilder help files to find if it has an option to set the classpath for you.


Java API Documentation
The Java Tutorial
Murali Nanchala
Ranch Hand

Joined: Mar 14, 2001
Posts: 74
USe this to set your required libraries in JBuilder (if you didn't know already).
Project-> Project Properties -> Required Libraries
You don't have to fill your system classpath with trash if you run everything from within JBuilder.


"It is almost always answered in the API" - Murali Nanchala
Murali Nanchala
Ranch Hand

Joined: Mar 14, 2001
Posts: 74
BTW, isn't trying to access the protected methods of a superclass in a different package is illegal?
Check this out:
http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html
Cheryl Gray
Ranch Hand

Joined: Nov 17, 2000
Posts: 44
Murali:
Thank you very much!!
Using Project Properties-> Required Libraries -> Add Project worked.
Also, accessing that method should not be a problem since my class is a subclass of the class in the other package.
 
 
subject: Import problems