我刚学android开发. 原来是做c.c++的.现在项目想用jni来调用c原来的代码.我碰到的问题是.
我在java里面写了如下的代码.
public class Protocol_type {
public class Proctocol_Type_Base {
public int fromType;
public int operationId;
}
public class Protocol_MsgNormal extends Proctocol_Type_Base {
int normalMsgType;
String fromAddr;
String content;
}
}jni里面写的是
public class readData {
static {
System.loadLibrary("readjni");
}
public native Proctocol_Type_Base Protocol_parseFromString(String telNo, String contentBuf);
}
在cpp里面是这样调用的.
static JNINativeMethod const gMethods[] =
{
{ "Protocol_parseFromString"," (Ljava/lang/String;Ljava/lang/String;)Lcom/example/data/Protocol_type/Proctocol_Type_Base;",(void*) java_Proctocol_from_CCP }
};编译没有问题.
但是一运行.平台会打印出,找不到本地方法.
请大家帮你看看.其实我想的就是返回一个内部类.但是不知道为什么老是说找不到本地方法,
我在java里面写了如下的代码.
public class Protocol_type {
public class Proctocol_Type_Base {
public int fromType;
public int operationId;
}
public class Protocol_MsgNormal extends Proctocol_Type_Base {
int normalMsgType;
String fromAddr;
String content;
}
}jni里面写的是
public class readData {
static {
System.loadLibrary("readjni");
}
public native Proctocol_Type_Base Protocol_parseFromString(String telNo, String contentBuf);
}
在cpp里面是这样调用的.
static JNINativeMethod const gMethods[] =
{
{ "Protocol_parseFromString"," (Ljava/lang/String;Ljava/lang/String;)Lcom/example/data/Protocol_type/Proctocol_Type_Base;",(void*) java_Proctocol_from_CCP }
};编译没有问题.
但是一运行.平台会打印出,找不到本地方法.
请大家帮你看看.其实我想的就是返回一个内部类.但是不知道为什么老是说找不到本地方法,
static {
System.loadLibrary("readjni");
}
public native Proctocol_Type_Base Protocol_parseFromString(String telNo, String contentBuf);
}
不是教你,你完全没看懂。
#include <string.h>
#include <jni.h>
jstring Java_mobile_jni_MyJniActivity_sayHelloWorld( JNIEnv* env,jobject thiz )
{
return (*env)->NewStringUTF(env, "Hello World");
}
才是。我这里没有c代码,直接在jni里用了“Hello World”,也可以写个。add(),add(3,5)填充。