Android NDK学习之旅
文章平均质量分 60
hkustwsh
靠软件开发吃饭的计算经济学学生...
展开
-
JNI - Getting Started
开始第一个JNI程序原创 2016-04-07 17:26:33 · 218 阅读 · 0 评论 -
JNI - Prevent JVM from crashing on Error Signals
In the previous article, Divide by Zero. A comparison between Java and C, we concluded that C++ programs will crash when it meets a DivideByZero Exception. Even with a handler, it will crash anyway.原创 2016-05-22 01:47:40 · 898 阅读 · 0 评论 -
JNI - Process ID
Conclustion: Java and C++ are in the same process.原创 2016-05-20 18:58:02 · 352 阅读 · 0 评论 -
JNI - Divide by Zero. A comparison between Java and C(1)
A comparison of DivideByZero(c++ and Java)原创 2016-05-19 17:00:55 · 491 阅读 · 0 评论 -
JNI - Exception Handling
.java file: class CatchThrow{ private native void doit() throws IllegalArgumentException; private void callback() throws NullPointerException{ throw new NullPointerException("CathThrow.callback原创 2016-04-20 16:01:20 · 346 阅读 · 0 评论 -
JNI - Call Method(Callback Call java methods from c)
.c file #include #include #include "InstanceMethodCall.h" JNIEXPORT void JNICALL Java_InstanceMethodCall_nativeMethod (JNIEnv *env, jobject obj){ jclass cls = (*env)->GetObjectClass(env,obj);原创 2016-04-09 21:14:42 · 1256 阅读 · 1 评论 -
JNI - Caching IDs
Method 1. Caching at the Point of Use static jmethodID cid = NULL; if (cid == NULL){ cid = (*env)->GetMethodID(env,stringClass,"","([C)V"); if (cid == NULL){ return NULL; } } Method 2原创 2016-04-18 19:51:17 · 222 阅读 · 0 评论 -
JNI - Static method. Method of SuperClass.
Call static method. jclass cls = *(env)->GetObjectClass(env,obj); jmethodID mid = (*env)->GetStaticMethodID(env, cls, "callback", "()V"; (*env)->CallStaticVoidMethod(env, cls, mid); Attention:原创 2016-04-10 00:21:15 · 299 阅读 · 0 评论 -
JNI - Method Signature.
Command line : javap -s -p Method_Call_Name Java method: class MethodDescriptor { MethodDescriptor(); private native java.lang.String getLine(java.lang.String); private native int GetLine(i原创 2016-04-09 22:12:06 · 763 阅读 · 0 评论 -
JNI - Field Descriptors.
class FieldDescriptors{ int intvalue; double doublevalue; float floatvalue; String stringvalue = new String(); int intarrayvalue[] = new int[5]; MyClass myclassvalue = new MyClass(); } How原创 2016-04-09 17:06:14 · 1404 阅读 · 0 评论 -
JNI - Access static field
class StaticFieldAccess{ private static int si; private native void accessField(); public static void main(String args[]){ StaticFieldAccess c = new StaticFieldAccess(); StaticFieldAccess.si =原创 2016-04-09 17:02:54 · 402 阅读 · 0 评论 -
JNI - Access an instance Field
.java File: class InstanceFieldAccess{ private String s; private native void accessField(); public static void main(String args[]){ InstanceFieldAccess c = new InstanceFieldAccess(); c.s =原创 2016-04-09 16:17:45 · 435 阅读 · 0 评论 -
JNI - PASS ARGUMENT. ObjectARRAY
.java file class ObjectArrayTest{ private static native int[][] initInt2DArray(int size); public static void main(String[] args){ int[][] i2arr = initInt2DArray(3); for (int i=0;i<3;i++){ fo原创 2016-04-08 19:31:20 · 333 阅读 · 0 评论 -
JNI - PASS ARGUMENT. array
.java file class IntArray{ private native int sumArray(int arr[]); public static void main(String[] args){ IntArray p = new IntArray(); int arr[] = new int[10]; for ( int i=0; i<10;i++) ar原创 2016-04-08 19:22:53 · 297 阅读 · 0 评论 -
JNI - PASS ARGUMENT. string
.c file: #include #include #include #include #include "Prompt.h" JNIEXPORT jstring JNICALL Java_Prompt_getLine (JNIEnv *env, jobject this, jstring prompt){ char buf[128]; const jbyte *str;原创 2016-04-08 19:05:07 · 421 阅读 · 0 评论 -
JNI - AttachCurrentThread
•The JNI interface pointer(JNIEnv) isvalid only in the current thread. •Should another thread need to access theJava VM, it must first call AttachCurrentThread() toattach itself to the VM and obt原创 2016-06-13 06:10:06 · 1469 阅读 · 1 评论