Java Eclipse 中的错误:方法...来自类型...指的是缺少的类型条目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16370305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error in Eclipse: The method ... from the type ... refers to the missing type Entry
提问by
I'm trying to use a function that uses the Entry
object but I am getting the above error message. The function looks like this:
我正在尝试使用使用该Entry
对象的函数,但收到上述错误消息。该函数如下所示:
public Entry<K,V> insert(K k, V v) throws InvalidKeyException {
//code here
}
I tried importing java.util.*
but that didn't work.
我尝试导入,java.util.*
但没有奏效。
Could someone please explain to me what this error message is telling me and how to resolve it?
有人可以向我解释这个错误消息告诉我什么以及如何解决它吗?
回答by atk
Trying to import java.util.*
was on the right track, because you are trying to use a class that isn't in the current namespace. The reason it didn't work is because Entry
isn't in the java.util
package. In order to import the class, you need to know what package the class is in.
尝试导入java.util.*
是在正确的轨道上,因为您正在尝试使用不在当前命名空间中的类。它不起作用的原因是因为Entry
它不在java.util
包中。为了导入类,您需要知道类在哪个包中。
Where did you find the Entry
class? If you read Entry
's javadoc, then go back and look at the javadoc and see what package it's in. If you are getting an Entry
object as the result of a call to another method, look at the javadoc for that method, then follow the link to the Entry
class, and see where Entry
is defined.
你在哪里找到的Entry
班级?如果您阅读了Entry
的 javadoc,则返回并查看 javadoc 并查看它在哪个包中。如果您Entry
通过调用另一个方法获得一个对象,请查看该方法的 javadoc,然后点击链接到Entry
类,看看在哪里Entry
定义。
If you are trying to use some custom Entry
class, be sure that you've defined it. If you haven't defined your custom Entry
class, it won't be defined when you try to use it.
如果您尝试使用某个自定义Entry
类,请确保您已经定义了它。如果你没有定义你的自定义Entry
类,当你尝试使用它时它不会被定义。
回答by wchargin
It's an inner classof Map
.
这是一个内部类的Map
。
Either
任何一个
import java.util.Map.Entry;
or
或者
public Map.Entry<K,V> insert(K k, V v) throws InvalidKeyException {
//code here
}