Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create an object with JNI?
    primarykey
    data
    text
    <p>I need to implement some functions into an Android application using NDK and thus JNI.</p> <p>Here's the C code, with my concerns, that I wrote:</p> <pre><code>#include &lt;jni.h&gt; #include &lt;stdio.h&gt; jobject Java_com_example_ndktest_NDKTest_ImageRef(JNIEnv* env, jobject obj, jint width, jint height, jbyteArray myArray) { jint i; jobject object; jmethodID constructor; jobject cls; cls = (*env)-&gt;FindClass(env, "com/example/ndktest/NDKTest/Point"); //what should put as the second parameter? Is my try correct, according to what //you can find in .java file? I used this documentation: http://download.oracle.com/javase/6/docs/technotes/guides/jni/spec/functions.html#wp16027 constructor = (*env)-&gt;GetMethodID(env, cls, "&lt;init&gt;", "void(V)"); //http://download.oracle.com/javase/6/docs/technotes/guides/jni/spec/functions.html#wp16660 //Again, is the last parameter ok? object = (*env)-&gt;NewObject(env, cls, constructor, 5, 6); //I want to assign "5" and "6" to point.x and point.y respectively. return object; } </code></pre> <p>My problems are more or less explained inside the code. Maybe also: is the return type of the function (jobject) ok?</p> <p>Now the NDKTest.java:</p> <pre><code>package com.example.ndktest; import android.app.Activity; import android.widget.TextView; import android.os.Bundle; public class NDKTest extends Activity { /** Called when the activity is first created. */ public native Point ImageRef(int width, int height, byte[] myArray); public class Point { Point(int myx, int myy) { x = myx; y = myy; } int x; int y; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView tv = new TextView(this); byte[] anArray = new byte[3]; for (byte i = 0; i &lt; 3; i++) anArray[i] = i; Point point = ImageRef(2, 3, anArray); tv.setText(String.valueOf(point.x)); setContentView(tv); } static { System.loadLibrary("test"); } } </code></pre> <p>When I try to run the code, it doesn't work.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload