views:

45

answers:

0

How do you stop this force close?? Im trying to load a c++ ndk library called helloCpp but using the following code. My program force closes as soon as it opens. I have checked that the libhelloCpp.so file is in the lib folder and it compiled with no errors.

//helloCpp.java
package com.knucklegames.helloCpp;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;

public class helloCpp extends Activity {

    static {
        System.loadLibrary("helloCpp");
    }

    private native String testFunction();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        String hello = testFunction();
        new AlertDialog.Builder(this).setMessage(hello).show();        
    }
}


//main.cpp

#include <jni.h>
#include <string.h>

extern "C" {
    JNIEXPORT jstring JNICALL Java_com_knucklegames_helloCpp_testFunction(JNIEnv * env, jobject obj);
};

JNIEXPORT jstring JNICALL Java_com_knucklegames_helloCpp_testFunction(JNIEnv *env, jobject obj) {
    return env->NewStringUTF("Hello from native code!");
}