aspose file tools*
The moose likes Beginning Java and the fly likes Import Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Import Problem" Watch "Import Problem" New topic
Author

Import Problem

Olivier Legat
Ranch Hand

Joined: Nov 17, 2007
Posts: 176

Hello everyone,

I'm having problems importing a class that doesn't belong to any package. My professor mentioned there is such a thing as the "blank" package, and that this class belongs to that package. How do I import it then?

In my imports I have:


and in my terminal (Windows) I type this:
javac -classpath .\sinf1160.jar;.\BarCode.class;.\Registre.class <filename>

The error i get is:


Suggestions? Please.


Olly
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
As far as I remember, it is not possible to import from the "default" package.
It is a compile time error to import a type from the unnamed package. See section 7.5.
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
I don't know this idea of a 'blank' package, I think the period'.' may be causing the problem, try to pt the class in a valid package (for example a new one) and then try a regular import.


be a well encapsulated person, don't expose your privates, unless you public void getWife()!
Olivier Legat
Ranch Hand

Joined: Nov 17, 2007
Posts: 176

Yes sorry, I think when I said the "blank" package I meant to say the "default" package. However if it can't be imported then I've got quite a big problem at hands because my professor just gave us the .class file so I can't put it in any other package if I wanted to... I guess I'll just ask him for help directly. Thanks for your help anyway guys
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
If you have a .class file you should be able to use it without requiring an import.
Or you could search for decompilers . . .
kishukishor patil
Greenhorn

Joined: Nov 20, 2008
Posts: 23

First it needs to tell that the class where you want to import u'r class is in default packge or in another package.

If it is in default packege then there is no need to import that class you can directly use that one.

like ..... import class1;
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14274
    
  21

Originally posted by Campbell Ritchie:
As far as I remember, it is not possible to import from the "default" package.

This used to be possible in older versions of Java, but it is not possible anymore since (I think) Java 5.

The only way to use classes in the "default" package is to put your own class in the "default" package (i.e., don't put a package statement in your code). But it's really not recommended to put classes in the "default" package. Your professor should really change his code and put his class Registre in a package.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Import Problem