Gui
Gui

Reputation: 115

Type is known, but method refers to missing type

I'm not very experienced with java and Eclipse and I'm getting the following problem:

I'm writing something like:

Point3D myPoint = myClass.myMethod(arg);

And I got the error:

the method myMethod(myType arg) refers to the missing type Point3D.

However the class Point3D is known, I can create an object of this type (Point3D) without error and I got Point3D methods from auto-completion.

Upvotes: 11

Views: 77398

Answers (5)

Neeraj Krishna
Neeraj Krishna

Reputation: 1615

If you have enabled Java module System without actually configuring it correctly this happens. I decided to remove the Java module system and use only the maven dependencies. In "Java Build Path" ensure that the Classpath dependencies are defined correctly.

Upvotes: 0

SpaceNet
SpaceNet

Reputation: 193

I got same issue, I solved it by changing the order of import. I put the class which make the issue at the top of import list, after package, then the IDE(VS code) makes no alert.

Upvotes: 2

Nick C
Nick C

Reputation: 1

Might depend on your context, but I was having the same issue too until I compiled it. Make sure that Eclipse didn't hide your import statements at the top of your program by minimizing a couple lines. I accidentally imported a file from a previous project of the same name and it hid the import statement at the top: "import A3.BST;". Just expand out to see your lines and delete the import statement and you should be fine.

Upvotes: 0

Dmitry Murashov
Dmitry Murashov

Reputation: 1

I had the same problem. It was solved with casting returning value of method to needed class - in your case Point3D

    private static ConcurrentHashMap<Long,HotelInfHQ> HASH_HOTELINF = new  ConcurrentHashMap<Long,HotelInfHQ>();

////

public static HotelInfHQ getHotelInfByKey (Long key){   
    return (HotelInfHQ)HASH_HOTELINF.get(key);
}

and in another class call was like

getHotelInfByKey(value);

Although ConcurrentHashMap HASH_HOTELINF was parametrized and Eclipse didn't show any mistake in return string, it was not obvious to it what class of object it returns at the point of method call

Upvotes: 0

Redtama
Redtama

Reputation: 1613

You are evidently using a different implementation of Point3D in the class where you have declared the method than where you are calling it.

Go to the declaration of myMethod and check that the import statement for Point3D in that class is the same as the import statement in the class where you are calling myMethod.

Upvotes: 3

Related Questions