Anyway, my next step is to learn how to compile native C++ code, access it in the Java portion, debug it, etc. I've installed and set up the NDK and Sequoyah in Eclipse, and I'm trying to write a basic "Hello World" app that generates a string in native code and displays it in a basic TextView. The project seems to be set up correctly, it has generated the jni folder with a .cpp and a .mk file inside. I edited the HelloAndroid.cpp File as follows:
- Code: Select all
#include <string.h>
#include <jni.h>
extern "C"
{
jstring Java_paulscode_android_helloandroid_HelloAndroid_sayHi( JNIEnv* env, jobject obj )
{
return env->NewStringUTF( "Howdy, this is JNI!" );
}
}
Then I edited the HelloAndroid.java File as follows:
- Code: Select all
package paulscode.android.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity
{
@Override
public void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
TextView tv = new TextView( this );
tv.setText( sayHi() );
setContentView( tv );
}
public native String sayHi();
}
The project compiles fine, but it fails to run in the AVD, generating the message "Sorry! The application Hello, Android (process paulscode.android.helloandroid) has stopped unexpectedly. Please try again."
Is there anything obviously wrong with my code, or are there some Eclipse or AVD settings that I need to check? Let me know if you require any further information about this Hello Android project to help me solve the problem.