vendredi 4 juillet 2014

(*env)->GetArrayLength(env, bytes) always returns 0


Vote count:

0




I'm new to Android Development, and just want to ask about little JNI code, I'm having a problem getting the right length of array passed in this code.


Here is my JNI code:



// jniexample.c
JNIEXPORT int JNICALL Java_com_example_HelloAndroid_getLength(JNIEnv * env, jobject obj, jbyteArray bytes)
{
jsize len = (*env)->GetArrayLength(env, bytes);
return len;
}


and here is the java code that calls it:



// com.example.HelloAndroid
public class HelloAndroid extends Activity
{
static
{
System.loadLibrary("jniexample");
}

public native int getLength(byte[] bytes);

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.chilli_main);
byte[] b = new byte[] { 0, 0, 0, 0, 0, 0, 0 };
new AlertDialog.Builder(this).setMessage(
"" + getLength(b)).show();
}
}


Everything works properly except that the method getLength(byte[]) always return 0.


Here is the link for screenshot (since I cannot post images yet)


http://ift.tt/1ko5pbP


Thanks in advance.



asked 52 secs ago






Aucun commentaire:

Enregistrer un commentaire