Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Import Problem

 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50258
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 352
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50258
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
Firefox Browser Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15492
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic