views:

864

answers:

4

Hi,

I am writing an android game. I need a Point class that stores x and y coordinates. I have found a class called java.awt.Point. Which looks like what I need. I have created an interface for java.awt.Point and put import java.awt.Point in my code. But when I do Point pos = new Point. I get an error: cannot instantiate Point. Also if I do pos. I don't get x or y member variables. I could code my own Point class but I need to learn how to import stuff.

If I delete the interface for Point I get an error on import java.awt.Point. It says the import cannot be resolved.

+5  A: 

Maybe just use android.graphics.Point instead?

I don't think there are any awt classes in Android other than NumericShaper and TextAttribute.

You can't create an interface for any class you want and hope it will be loaded automatically, save for instantiating it - interface is only a description. Android doesn't include the full Java Class Library, just a subset.

Here's a full list of currently used packages by Android.

macbirdie
+4  A: 

For Point class use android.graphics.Point

import android.graphics.Point;

bhatt4982
+1  A: 

The Android JVM does not have the full Java SE class library, nor does it conform to any J2ME profile. You can see which classes are part of the library here - AWT is missing completely. However, the android class library has its own Point and PointF classes for int and float coordinates.

Michael Borgwardt
+1  A: 

In this case I think it's best to write your own Point class since java.awt.Point belongs to the AWT framework and using it outside this context is not really a good practice.

However if it's just an exercise in importing stuff it's ok. The error you get when trying to instantiate your interface (also named Point I presume) is normal you cannot instantiate a interface.

The second error where the import cannot be resolved is likely because the the AWT JAR is not added to your classpath. Are you using a IDE?

You should start with a basic Java tutorial I guess, but I can't seem to find a good one online at the moment. Maybe someone else knows where to find one.

NickDK