I am trying to implement OpenFeint for Android in my cocos2d-x project. My approach so far has been creating a button that calls a static java method in class Bridge using jnihelper functions (jnihelper only accepts statics).

Bridge has one singleton attribute of type OFAndroid, that is the class dynamically calling the Openfeint Api methods, and every method in the bridge just forwards it to the OFAndroid object.

What I am trying to do now is to initialize the openfeint libraries in the main java class that is the one calling the static C++ libraries. My problem right now is that the initializing function

void com.openfeint.api.OpenFeint.initialize(Context ctx, OpenFeintSettings settings, OpenFeintDelegate delegate) 

is not accepting the context parameter that I am giving him, which is a "this" reference to the main class. Main class extends from Cocos2dxActivity but I don't have any other that extends from Application.

Any suggestions on fixing it or how to improve the architecture?


I am trying a new solution. Make the bridge class into an Application child, is called from Main object, initializes OpenFeint when created and it can call the OpenFeint functions instead of needing an additional class.

The problem is I still get the error.

03-30 14:39:22.661: E/AndroidRuntime(9029): Caused by: java.lang.NullPointerException
03-30 14:39:22.661: E/AndroidRuntime(9029):     at android.content.ContextWrapper.getPackageManager(ContextWrapper.java:85)
03-30 14:39:22.661: E/AndroidRuntime(9029):     at com.openfeint.internal.OpenFeintInternal.validateManifest(OpenFeintInternal.java:885)
03-30 14:39:22.661: E/AndroidRuntime(9029):     at com.openfeint.internal.OpenFeintInternal.initializeWithoutLoggingIn(OpenFeintInternal.java:829)
03-30 14:39:22.661: E/AndroidRuntime(9029):     at com.openfeint.internal.OpenFeintInternal.initialize(OpenFeintInternal.java:852)
03-30 14:39:22.661: E/AndroidRuntime(9029):     at com.openfeint.api.OpenFeint.initialize(OpenFeint.java:47)
03-30 14:39:22.661: E/AndroidRuntime(9029):     at nurogames.fastfish.NuroFeint.onCreate(NuroFeint.java:23)
03-30 14:39:22.661: E/AndroidRuntime(9029):     at nurogames.fastfish.FastFish.onCreate(FastFish.java:47)
03-30 14:39:22.661: E/AndroidRuntime(9029):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
03-30 14:39:22.661: E/AndroidRuntime(9029):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)

The problem was in the Android manifest. My main class inheriting from Application was not added as the main application class in the description.

Once added, the app called a new object and the OnCreate method where I could initialize OpenFeint. As OpenFeint is open you can now statically call the OpenFeint functions to open the different views.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.