• 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

Import Problem

 
Ranch Hand
Posts: 176
Mac Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Chrome Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 . . .
 
Greenhorn
Posts: 23
Firefox Browser Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic