• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Import problems

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Murali Nanchala
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic