jni - java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() -



jni - java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() -

i getting exception when trying phone call non-static method in java class jni.the exception getting is:

can't create handler within thread has not called looper.prepare()

here jni calling code:

jclass mclass = env->findclass("com/secrethq/match3/match3activity"); jmethodid constructor = env->getmethodid( mclass, "<init>", "()v"); cclog("jclass located?"); jobject object = env->newobject(mclass, constructor); mid = env->getmethodid(mclass, "onclickpoststatusupdate", "(i)v"); cclog("mid: %d", mid); if (mid!=0) env->callvoidmethod(mclass, mid, object, score); //----------------------------------------------------------- cclog("finish"); if(isattached) jvm->detachcurrentthread();

and method in java class:

private void onclickpoststatusupdate(int score) { system.out.println("match3activity.onclickpoststatusupdate()"); performpublish(pendingaction.post_status_update, canpresentsharedialog); }

here logcat output:

06-22 20:20:39.342: e/androidruntime(14899): java.lang.runtimeexception: can't create handler within thread has not called looper.prepare() 06-22 20:20:39.342: e/androidruntime(14899): @ android.os.handler.<init>(handler.java:121) 06-22 20:20:39.342: e/androidruntime(14899): @ android.app.activity.<init>(activity.java:772) 06-22 20:20:39.342: e/androidruntime(14899): @ org.cocos2dx.lib.cocos2dxactivity.<init>(cocos2dxactivity.java:37) 06-22 20:20:39.342: e/androidruntime(14899): @ com.secrethq.match3.match3activity.<init>(match3activity.java:45) 06-22 20:20:39.342: e/androidruntime(14899): @ org.cocos2dx.lib.cocos2dxrenderer.nativetouchesend(native method) 06-22 20:20:39.342: e/androidruntime(14899): @ org.cocos2dx.lib.cocos2dxrenderer.handleactionup(cocos2dxrenderer.java:129) 06-22 20:20:39.342: e/androidruntime(14899): @ org.cocos2dx.lib.cocos2dxglsurfaceview$9.run(cocos2dxglsurfaceview.java:258) 06-22 20:20:39.342: e/androidruntime(14899): @ android.opengl.glsurfaceview$glthread.guardedrun(glsurfaceview.java:1462) 06-22 20:20:39.342: e/androidruntime(14899): @ android.opengl.glsurfaceview$glthread.run(glsurfaceview.java:1240)

the line:

jobject object = env->newobject(mclass, constructor);

attempts instantiate activity. in general, aren't supposed instantiate activities hand, meant create them using designated android apis, e.g. context.startactivity.

by circumventing api, you've gotten in situation create activity in thread not back upwards creation of activity.

that's cause of error. also: want rethink code whole. not sure you're trying do, doesn't seem pattern you're using right one.

java jni cocos2d-x

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -