• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error When Importing

 
Sean Magee
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


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.*;
 
Sean Magee
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, its a class I made myself. I thought I could import is using " import Person; "
 
Anish Tho
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
[ref:http://mindprod.com/jgloss/import.html]

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 ]
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic