Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.NoClassDefFoundError: java.awt.Point

I am using Android Studio for developing a LibGDX based game for android devices. I have imported "Point" from java.awt.Point. I have tested it using the 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. Please advice on how to solve this .

            Point p=new  Point(toyCells[i][0] + toyCellsAdjecentCells[j][0],
                               toyCells[i][1] + toyCellsAdjecentCells[j][1]);
like image 623
iappmaker Avatar asked May 12 '26 09:05

iappmaker


2 Answers

This is because Android does not support awt (or Swing). These are graphic libraries to be used when developing computer applications. Try to use

android.graphics.Point

instead.

like image 70
milez Avatar answered May 13 '26 22:05

milez


milez has the correct answer. Android doesn't have the Point class that you're using for the DesktopLauncher.

However, one thing you should note: LibGDX is supposed to work in a device-independent manner. 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. That's pretty simple, and it has next to no overhead.

You could also use the Point-like class LibGDX provides called 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.

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

It also gives you some useful math options like translate(dx, dy) or angle(). Use this one if you're interested in doing more options than just storing two integer values.

like image 36
Lee Presswood Avatar answered May 13 '26 22:05

Lee Presswood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!