SimpleApplication subclass Instantiation problem on android 3.1 device


I have developed a SimpleApplication subclass “BorderGame” that runs perfectly on my PC. However, when I deploy my application to an Android 3.1 tablet, the application crashes with exception:

mygame.BorderGame: java.lang.InstantiationException

Class mygame.BorderGame init failed: at java.lang.Class.newInstanceImpl(Native)

at java.lang …

I have realized that the crash occurs because BorderGame has a constructor with parameters:

public class BorderGame extends SimpleApplication {

public BorderGame(float length,float width, String floort,boolean west,boolean east, boolean north,boolean south){…}

If I remove the parameters and I create an instance with new BorderGame() the exception is not raised. I am curious about whether SimpleApplication subclasses to be deployed on Android devices may not have constructors with parameters.

If this is so, do I have to create the object first with

b=new BorderGame();

and then do something like

b.setinitValues(//values from “main” function args vector) ??

BTW I need these values to be passed to my BorderGame object (I can’t include them in “simpleInitApp”) because they are external configuration values obtained from the main “args” vector

Thanks for your help

If you look at the AndroidHarness class, you’ll see that the derived SimpleApplication class is instantiated using Class#newInstance.

Is it essential that the values are passed in before BorderGame starts (i.e, before simpleInitApp() is called)?

EDIT: Android and a main method? You sure about that? :wink:

you’re right , it is not essential. I will read those parameters from a Conf File on SimpleInitApplication.


PS: Yes, I have a static main method in my class. Is there anything wrong with it?