• 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

Error When Importing

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, its a class I made myself. I thought I could import is using " import Person; "
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic