File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Error When Importing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Error When Importing" Watch "Error When Importing" New topic

Error When Importing

Sean Magee
Ranch Hand

Joined: Aug 23, 2004
Posts: 69
When I try to import a class it says

Does anyone know why?
[ December 02, 2004: Message edited by: Sean Magee ]
Jimmy Die
Ranch Hand

Joined: Nov 20, 2003
Posts: 97

The output

import Person;

Looks very supicious. Does your import statement in your class read

import Person;


If you want to import all classes in your package it would look more like

import Person.*;

Jimmy Die
Sean Magee
Ranch Hand

Joined: Aug 23, 2004
Posts: 69
No, its a class I made myself. I thought I could import is using " import Person; "
Anish Tho

Joined: Dec 02, 2004
Posts: 1
You must not import classes in the same package as the current class. If you are using the default nameless package, you must not import any other classes in the default package.

if both Person and sean classes are in the same directory, you can use "Person" class in "sean" without importing it.
Also do make the constructor in Person class public, if you want to access it from outside.

public class sean{
Person p = new Person("hi",1);
[ December 03, 2004: Message edited by: Anish Tho ]

Thanks<br />Anish
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

The import command assumes that you are importing a class not in the root(default) package. Thus, there must be a dot in statement. You cannot import from the root package --not that there is a need to anyway; in that case, simply use the class and the JVM will find it.

So, if your Person class is in a package, then you would say

import my.package.Person

Otherwise, there is no need to issue an import statement.

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Oh, yeah, I remember that one! The 1.3 parser/compiler we used in Visual Age did not enforce the "no import from current package" rule, but Sun's 1.4 did, so a lot of code that compiled in our system just fine failed in JavaDoc run outside the IDE. Very confusing. You may find old examples and sample code that give you trouble, too.

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: Error When Importing
It's not a secret anymore!