简体   繁体   English

java.lang.NoClassDefFoundError:java.awt.Point

[英]java.lang.NoClassDefFoundError: java.awt.Point

I am using Android Studio for developing a LibGDX based game for android devices. 我正在使用Android Studio为Android设备开发基于LibGDX的游戏。 I have imported "Point" from java.awt.Point. 我已经从java.awt.Point导入了“ Point”。 I have tested it using the DesktopLauncher. 我已经使用DesktopLauncher对其进行了测试。 It works fine. 工作正常。

Issue : When I loaded it in Android device, I am getting error "java.lang.NoClassDefFoundError: java.awt.Point" when I reach the line below. 问题:当我将其加载到Android设备中时,到达以下行时出现错误“ java.lang.NoClassDefFoundError:java.awt.Point”。 Please advice on how to solve this . 请提供有关如何解决此问题的建议。

            Point p=new  Point(toyCells[i][0] + toyCellsAdjecentCells[j][0],
                               toyCells[i][1] + toyCellsAdjecentCells[j][1]);

This is because Android does not support awt (or Swing ). 这是因为Android不支持awt (或Swing )。 These are graphic libraries to be used when developing computer applications. 这些是开发计算机应用程序时要使用的图形库。 Try to use 尝试使用

android.graphics.Point

instead. 代替。

您是否应该使用com.badlogic.gdx.math.GridPoint2D而不是java.awt.Point

milez has the correct answer. milez有正确的答案。 Android doesn't have the Point class that you're using for the DesktopLauncher. Android没有用于DesktopLauncher的Point类。

However, one thing you should note: LibGDX is supposed to work in a device-independent manner. 但是,您应该注意一件事:LibGDX应该以与设备无关的方式工作。 This means the code shouldn't require changing between devices. 这意味着代码不需要在设备之间进行更改。 Therefore, you need to find a solution that is device-independent. 因此,您需要找到与设备无关的解决方案。

You have two options: 您有两种选择:

You could create your own MyPoint class that has an X and Y integer field in it. 您可以创建自己的MyPoint类,其中包含X和Y整数字段。 That's pretty simple, and it has next to no overhead. 这很简单,几乎没有开销。

You could also use the Point-like class LibGDX provides called Vector2. 您还可以使用类似点的类LibGDX提供的称为Vector2的类。 This class is guaranteed to work on all devices: 此类可以在所有设备上使用:

Vector2 point = new Vector2(x, y);

For this option, calling point.x would give you the float representation of whatever X you passed in. This float value would have to be casted to an integer if you wanted to use it in an array, however. 对于此选项,调用point.x将为您提供传入的X的浮点表示形式。但是,如果要在数组中使用它,则必须将该浮点值强制转换为整数。

my_x = my_array[(int) point.x];

It also gives you some useful math options like translate(dx, dy) or angle(). 它还为您提供了一些有用的数学选项,例如translate(dx,dy)或angle()。 Use this one if you're interested in doing more options than just storing two integer values. 如果您有兴趣做更多的选择而不只是存储两个整数值,请使用此选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM