SJ19
SJ19

Reputation: 2123

Android/Java: How to import classes in a subpackage from another sub-package?

First of all I'm not sure if this is Android specific, I have two packages with a subclass and I'm trying to import one subclass from the other subclass which doesn't seem to work. This has never occurred to me before, am I not supposed to do this?

Here you can see the error, "Exercise" cannot be resolved, yet I have tried to import it but that doesn't seem to work either.

error package cannot resolve

All good when I move class "Exercise" into package "database".

good package good

Upvotes: 1

Views: 745

Answers (1)

R. Karlus
R. Karlus

Reputation: 2276

Just check your Exercise class declaration. If it is declared this way:

class Exercise {...}

You will never be able to import it because this is called package declaration which means that you only can declare it if you are in it's package. Do you understand? That's why when you move the class to the DatabaseQuery package, it works fine.

But if the declaration of your class is something like:

public class Exercise {...}

Then you need to check your environment, clean caches or restart your IDE.

Upvotes: 1

Related Questions