============问题描述============
这是xcode下的代码 #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) JniMethodInfo minfo; bool isHave = JniHelper::getStaticMethodInfo(minfo,"org/com/TestFirst/ProcessManager","getInstance","()Ljava/lang/Object;"); CCLog("开始调用!"); jobject jobj=NULL; if (isHave) { jobj = minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID); } CCLog("取得jobj"); isHave = JniHelper::getMethodInfo(minfo,"org/com/TestFirst/ProcessManager","getProcess","()V"); CCLog("处理中!"); std::cout<<isHave<<std::endl; if (isHave) { CCLog("接收!"); minfo.env->CallVoidMethod(jobj, minfo.methodID); CCLog("完成!"); } else { CCLog("jni-java函数执行完毕"); } #endif ---------------------------------------------------------------- 下面是eclipse下的java代码 package org.com.TestFirst; import org.cocos2dx.lib.Cocos2dxActivity; import android.app.Activity; import android.app.ActivityManager; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.widget.Button; import android.widget.TextView; public class ProcessManager extends Cocos2dxActivity{ private static String TAG = "AM_MEMORYIPROCESS" ; private ActivityManager mActivityManager = null ; public static ProcessManager actInstance=null;//定义单例 public static Object getInstance() { if(actInstance==null) { actInstance=new ProcessManager(); } Log.d("daa", "fsfsdf"); return actInstance; } protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); } public void getProcess() { Log.d("cocosAct","go on!!!"); } } 执行以后,在LogCat里面能够看到xcode下打的log,但执行到minfo.env->CallVoidMethod(jobj, minfo.methodID),然后就崩了. getProcess()里的log没有打印出来,这种调用非静态函数的方法在网上找的,大家都是这么写,不知道我错在哪里,求各位大侠帮忙解决解决.============解决方案1============
引用 2 楼 u012240007 的回复:Quote: 引用 1 楼 luowenlong860502 的回复:难怪啊,Activity是运行在UI线程的,你在其他地方怎么能调用它的成员方法呢?只能Activity本身能调用如果是在另外的线程中调用请检查是否有 (g_jvmInstance)->AttachCurrentThread(&env, NULL);最开始的时候我并没有让ProcessManager类继承Activity类,这样调用非静态函数不会错,不过继承Activity类以后就出错了.