2

I'm currently able to compile a class that has this import statement:

import com.panframe.android.lib.*;

But there is no external dependency which satisfies this statement. The code somehow uses this import statement. Even Android Studio warns me about this non existent class:

enter image description here

How I am able to compile this class? Shouldn't compiler prevent this from happening?

matesio
  • 1,584
  • 17
  • 31
Yigit Unlu
  • 21
  • 1
  • 3
  • 1
    The import statement says "import everything from the package com.panframe.android.lib". And it does - since there is nothing in that package, it imports nothing. This is one of the reasons why using wildcard imports is not considered a good idea by many people. – Erwin Bolwidt Jun 19 '19 at 07:37
  • I added the image directly into the post, but it would be better if you post the code itself and not an image of it. – lealceldeiro Jun 19 '19 at 07:37
  • The image doesn't contain anything concerning the import or an error. Do you reveice a specific warning message? – Zhedar Jun 19 '19 at 07:44
  • You can create some stub classes to replace the external dependency. Then you can compile your class without error. But you cannot run your code correctly with there stub classes. – Esc Điệp Jun 19 '19 at 07:45
  • 1
    @lealceldeiro I usually agree but seeing unresolved references is easier with an image. – Yigit Unlu Jun 19 '19 at 07:57

2 Answers2

2

This is because you don't reference any specific class.
The character * in this case stands for a wildcard import, which imports every class in the package com.panframe.android.lib.

Without knowing anything about your package structure, I guess you have some classes in the package com.panframe.android.lib. Otherwise you would get an error.

Zhedar
  • 3,480
  • 1
  • 21
  • 44
  • I don't have any classes with package ```com.panframe.android.lib``` – Yigit Unlu Jun 19 '19 at 07:58
  • Is this code under your control? Can you simply remove the import statement? Do you have any subpackages under `com.panframe.android.lib`? See https://stackoverflow.com/questions/16976064/java-cant-import-com-package-wildcard – Zhedar Jun 19 '19 at 08:00
  • When I remove the import statement it does not compile anymore. When I replace wildcard with FQCNs it does not compile either. – Yigit Unlu Jun 19 '19 at 08:04
  • What errors do you get, if you remove the import statement? – Zhedar Jun 19 '19 at 08:05
  • I do not have anything that relates to ```com.panframe.android.lib``` – Yigit Unlu Jun 19 '19 at 08:09
  • basicly "error: cannot find symbol" for every class referenced which is red in the image – Yigit Unlu Jun 19 '19 at 08:10
  • Is this your first (and only?) library you added to your project(s)? Maybe you didn't add it the the classpath correctly. You could also try to auto organize the imports, if you dont add them automatically yet. ( https://stackoverflow.com/questions/22272524/how-to-auto-import-the-necessary-classes-in-android-studio-with-shortcut/29967269 ) – Zhedar Jun 19 '19 at 08:15
  • I'm using gradle to organize dependencies. This class (and the project) compiles. The import does not relate to any external dependencies but I have nearly 100 external dependencies. This project is currently working, on the production project. Somehow required dependency is removed and I'm left with an unsatisfiable dependency. Even tho I can still compile this. – Yigit Unlu Jun 19 '19 at 08:20
0

Turns out I was wrong. Needed references was in libs folder, and Android Studio was not able to see these references.

It was an Android Studio bug, updating it fixed my issue.

Yigit Unlu
  • 21
  • 1
  • 3