【发布时间】:2014-11-30 11:48:33
【问题描述】:
所以我的类扩展了 Actor,我想使用 getLocation() 方法,它需要来自 Actor 的位置,但它会将我发送到需要 Point 的 java.awt.Point 的 getLocation()
public class Myplayer extends Actor
Location myLocation = player.getLocation();
错误:
incompatible types: java.awt.Point cannot be converted to ch.aplu.jgamegrid.Location
这是两个库的链接:
演员:http://www.aplu.ch/classdoc/jgamegrid/index.html
获取位置
public Location getLocation()
Returns the current location (horizontal and vertical coordinates).
Returns:
a clone of the current location (cell indices)
点:http://docs.oracle.com/javase/7/docs/api/java/awt/Point.html#getLocation%28%29
获取位置
public Point getLocation()
Returns the location of this point. This method is included for completeness,
to parallel the getLocation method of Component.
Returns:
a copy of this point, at the same location
如何在不使用 Point 的情况下解决此问题?
编辑:
import ch.aplu.jgamegrid.*;
import java.awt.Color;
import java.util.*;
public class MyPlayer extends Actor
private Players player
public Location myLocation() {
return player.getLocation();
【问题讨论】:
-
请在myplayer中显示
getLocation的定义,以及player变量的定义。最好发布你的完整课程,只删除你认为不相关的方法。 -
同时发布你在 myplayer 类中导入的内容
-
最好编辑您的问题,因为它更具可读性。你也应该发布你的相关课程。
-
那么,既然您已经编辑了,我们可以看到播放器不是
MyPlayer类型。所以MyPlayer是否扩展Actor并不重要。如果你真的需要进一步的帮助,你必须解释你真正的问题,并发布你的完整代码,在上下文中解释出了什么问题。
标签: java methods libraries incompatibility incompatibletypeerror