Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / March 2005

Tip: Looking for answers? Try searching our database.

Import problem

Thread view: 
Martin Kjeldsen - 30 Mar 2005 10:26 GMT
Hi all,
I am new to Eclipse and already have a problem with imports.
The problem is this: If there is 2 packages (pack1 and pack2) both in the
/src
directory then when I try to import pak2 from a class in pak1,  pak2 cannot
be resolved.
I imagine it has something to do with the classpath, which currently has
these entries:

<classpathentry kind="src" path="src"/>

<classpathentry sourcepath="JRE_SRC" kind="var" path="JRE_LIB"/>

<classpathentry kind="output" path="bin"/>

Any help is greatly appreciated.

Regards
Martin Kjeldsen
Robert Klemme - 30 Mar 2005 10:44 GMT
> Hi all,
> I am new to Eclipse and already have a problem with imports.
[quoted text clipped - 11 lines]
>
> <classpathentry kind="output" path="bin"/>

Unlikely.  Please show your import statements.  I suspect a spelling error
or such.

   robert
Martin Kjeldsen - 30 Mar 2005 11:33 GMT
I tried refering to the class from the other package by its full name
(pack2.OtherPack) from MainPack and that worked fine.
So you have a point about the problem being the actual import statements.
Here is the source that fails on "import pack2":

src\pack1\pack1.java:

package pack1;
import pack2;

public class MainPack {

public static void main(String[] args) {
 OtherPack op = new OtherPack();
 op.print();
}
}

src\pack2\pack2.java:

package pack2;

public class OtherPack {
public void print(){
 System.out.println("Hello");
}
}

----- Original Message -----
From: "Robert Klemme" <bob.news@gmx.net>
Newsgroups: comp.lang.java.softwaretools
Sent: Wednesday, March 30, 2005 11:44 AM
Subject: Re: Import problem

> > Hi all,
> > I am new to Eclipse and already have a problem with imports.
[quoted text clipped - 16 lines]
>
>     robert
Ulf_N - 30 Mar 2005 22:22 GMT
Martin Kjeldsen skrev:
> I tried refering to the class from the other package by its full name
> (pack2.OtherPack) from MainPack and that worked fine.
[quoted text clipped - 53 lines]
>>
>>    robert

You must import a type, not a package.
This should import all types (classes and interfaces) in pack2:

import pack2.*;

/ulf


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.