
请问在android开发中,如何问在jni中调用java类的用synchronized修饰的静态方法
请问在android开发中,如何在jni中调用java类的用synchronized修饰的静态方法用GetStaticMethodID查找方法时,报错,java.lang...
请问在android开发中,如何在jni中调用java类的用synchronized修饰的静态方法
用GetStaticMethodID查找方法时,报错,java.lang.NoSuchMethodError.
急,解决了再追加100分。谢谢
我是这样做的
jclass ActivityManager = (*env)->FindClass(env,"com/curllion/tools/ActivityManager");
jmethodID getAdManagerInstance =(*env)->GetStaticMethodID(env,ActivityManager,"getInstance","(Landroid/content/Context;)Lcom/curllion/tools/ActivityManager");
在java中,是这样写的
public statice synchronized
ActivityManager getInstance(Context context); 展开
用GetStaticMethodID查找方法时,报错,java.lang.NoSuchMethodError.
急,解决了再追加100分。谢谢
我是这样做的
jclass ActivityManager = (*env)->FindClass(env,"com/curllion/tools/ActivityManager");
jmethodID getAdManagerInstance =(*env)->GetStaticMethodID(env,ActivityManager,"getInstance","(Landroid/content/Context;)Lcom/curllion/tools/ActivityManager");
在java中,是这样写的
public statice synchronized
ActivityManager getInstance(Context context); 展开
4个回答
展开全部
调用是跟普通的静态方法一样调用(类名.方法名),但是同一时间只能有一个线程能调用,就是说不管你什么时候调用这个方法,都会检查这个方法是否在使用中,如果是的话要等使用这个方法的线程结束之后才可以调用。
建议楼主去复习一下synchornized关键字
建议楼主去复习一下synchornized关键字
追问
请看清我的问题
在JNI中,查找java类的静态方法时,如果这个方法带有synchornized关键字,就无法用GetStaticMethodID找到这个方法的ID,如果不带这个关键字,是可以找到的。
我当然知道synchornized关键字是干嘛的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Calling Static Methods
GetStaticMethodID
jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz,
const char *name, const char *sig);
Returns the method ID for a static method of a class. The method is specified by its name and signature.
GetStaticMethodID() causes an uninitialized class to be initialized.
LINKAGE:
Index 113 in the JNIEnv interface function table.
PARAMETERS:
env: the JNI interface pointer.
clazz: a Java class object.
name: the static method name in a 0-terminated modified UTF-8 string.
sig: the method signature in a 0-terminated modified UTF-8 string.
RETURNS:
Returns a method ID, or NULL if the operation fails.
THROWS:
NoSuchMethodError: if the specified static method cannot be found.
ExceptionInInitializerError: if the class initializer fails due to an exception.
OutOfMemoryError: if the system runs out of memory.
从文档的内容看调用静态函数是使用这个函数没有问题
1、由于你没提供详细的同步函数声明及C的调用,所以不知道你的调用是否有问题
2、可以变通一下,另定义一个非同步函数,它调用同步函数,然后在jni里调用这个非同步函数
GetStaticMethodID
jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz,
const char *name, const char *sig);
Returns the method ID for a static method of a class. The method is specified by its name and signature.
GetStaticMethodID() causes an uninitialized class to be initialized.
LINKAGE:
Index 113 in the JNIEnv interface function table.
PARAMETERS:
env: the JNI interface pointer.
clazz: a Java class object.
name: the static method name in a 0-terminated modified UTF-8 string.
sig: the method signature in a 0-terminated modified UTF-8 string.
RETURNS:
Returns a method ID, or NULL if the operation fails.
THROWS:
NoSuchMethodError: if the specified static method cannot be found.
ExceptionInInitializerError: if the class initializer fails due to an exception.
OutOfMemoryError: if the system runs out of memory.
从文档的内容看调用静态函数是使用这个函数没有问题
1、由于你没提供详细的同步函数声明及C的调用,所以不知道你的调用是否有问题
2、可以变通一下,另定义一个非同步函数,它调用同步函数,然后在jni里调用这个非同步函数
更多追问追答
追问
试过非同步函数,是可行的,但是同步函数找不出来,很是郁闷
追答
你能把相关代码贴出来么?
从java反射机制上看,synchronized修饰符与查Class的方法无关呀,试试Class.getMethod(String name, Class[] parameterTypes)就知道了,这个跟C里的方法在机制上应该是一致的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询