1

I Already read this, this and this before posting my question.

My problem is slightly different.

I'm a beginner in java and I have a jar file that I need to use in my project (I beleive it is called library). I imported it to my netbean libraries folder using import jar/folder option and I can see content of the library. Unfortunately the class that I need to import is under default package and using import rearrange; (rearrange is name of class) is not working.

To understand how to use this class I decompiled a class file that is importing exact same class and surprisingly it uses import rearrange; to import that class.

I know that I cannot import classes from default package. and my sample class is not using reflection either.

What I'm doing wrong and how can I import this class? I also know that library (jar file) and also my sample class are compiled with java 1.6 (they didn't use 1.3.x that was allowing this type of import)

Community
  • 1
  • 1
AaA
  • 3,600
  • 8
  • 61
  • 86
  • 4
    As you can see from those questions, classes from default package can't be imported! – Jomoos Jul 21 '12 at 04:22
  • If you know classes in the default package can't be imported, why are you trying to do it? And why do you put classes in the default package? And why don't you respect naming conventions (class start with an upper-case letter). Best practices exist for a reason. Not following them invariably leads to problems. – JB Nizet Jul 21 '12 at 07:10
  • @JBNizet, Thank you for your advice! I was expecting an answer! I believe you didn't read my question properly, I did not put classes in default package, it was there and somehow it was used from there, unless I'm making a mistake. for the naming conventions, I didn't name the package, I'm trying to use it. if you like to scold the guy who did this, I can give you his name and address so you can go to his house and do what ever you like to him! – AaA Jul 21 '12 at 07:49
  • @BobSort: no need to take it like that. The guy did a big mistake by putting a reusable class, part of a library, in the default package. He did something wrong. You didn't do anything wrong. Fine. If you know the guy, ask him to refactor his code and release another version of his library. As simple as that. And read your own question. It literally says: "I know I can't import classes from default package" and then "how can I import this class [which is in the default package]". So write the answer to your own question: you can't. It's that simple. – JB Nizet Jul 21 '12 at 09:30
  • the company that developed the component gave me 16 weeks estimated fix time, and I can't wait that long. I found a dirty solution myself. I recompiled their classes and moved them to a named package, until they send me the fix. fortunately code works fine and my problem is solved. I think I could put my code inside their package and it might worked as well, but didn't try it. – AaA Jul 23 '12 at 07:37

0 Answers0