[英]define return value for java method in native file in android native app
In define findclass and getmethodid in Android native app, I have an method that returns a value of Uri.在 Android 本机应用程序中定义 findclass 和 getmethodid 时,我有一个返回 Uri 值的方法。
below is my native code:下面是我的本机代码:
void Java_com_example_myapp_MainActivity_callnative(JNIEnv* env, jobject obj){
jclass handlerClass = (*env)->FindClass(env, "com/example/myapp/myclass");
jmethodID parsemethod = (*env)->GetMethodID(env, handlerClass, "methodname", "(Ljava/lang/String;)Landroid/net/Uri");
}
MainActivity code:主要活动代码:
public class MainActivity extends ActionBarActivity {
private static String LIB_NAME = "nativelib";
static {
System.loadLibrary(LIB_NAME);
}
public native void callnative();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
callnative();
}
}
and myclass code which has a method(show) and Native code will call this method:和具有方法(显示)和本机代码的 myclass 代码将调用此方法:
public class myclass {
public Uri show(Uri Uri)
{
Log.v("called from native", "calling from native side");
return Uri.parse("content://this/string");
}
}
I get this error: Java.lang.NoSuchMethodError: no method with name ="methodname" signature=' (Ljava/lang/String;) Landroid/net/Uri' in class Lcom/example/myapp/myclass;我收到此错误:Java.lang.NoSuchMethodError: no method with name ="methodname" signature=' (Ljava/lang/String;) Landroid/net/Uri' in class Lcom/example/myapp/myclass;
suppose this is for Define Return value, for return value like Void we set Only V, but I do not have any idea about Uri.假设这是用于定义返回值,对于像 Void 这样的返回值,我们只设置 V,但我对 Uri 一无所知。
How can I fix this?我怎样才能解决这个问题?
您可能正在从java
static
方法调用本机方法,只需从MainActivity
删除关键字static
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.