Hi, I want to call the java method from c++ level, so I use jni way by JNIHelper.
In my Java class, there is a method like:
private void onCallFromCpp() {
Log.d(“###”, “Call from C++”);
}
this code is work good and i can see the message is print in logcat.
but i changed the method like:
private void onCallFromCpp() {
Log.d(“###”, “Call from C++”);
runOnUiThread(new Runnable() {
public void run() {
// Do nothing here… but crashed…
}
});
}
The message is print in logcat BUT app exited suddenly. I just want to call some method which must be called in Android UI thread.
What should i do?
Hi, I want to call the java method from c++ level, so I use jni way by JNIHelper.
>
In my Java class, there is a method like:
>
private void onCallFromCpp() {
Log.d(“###”, “Call from C++”);
}
>
this code is work good and i can see the message is print in logcat.
>
but i changed the method like:
>
private void onCallFromCpp() {
Log.d(“###”, “Call from C++”);
runOnUiThread(new Runnable() {
public void run() {
// Do nothing here… but crashed…
}
});
}
The message is print in logcat BUT app exited suddenly. I just want to call some method which must be called in Android UI thread.
What should i do?
As I known , JNI method should be static , so you should change onCallFromCpp to static , after you change it , you should do another thing : give a activity to that Java class , because runOnUiThread is a method of Activity!
5 Jan wrote:
> Hi, I want to call the java method from c++ level, so I use jni way by JNIHelper.
>
> In my Java class, there is a method like:
>
> private void onCallFromCpp() {
> Log.d(“###”, “Call from C++”);
> }
>
> this code is work good and i can see the message is print in logcat.
>
> but i changed the method like:
>
> private void onCallFromCpp() {
> Log.d(“###”, “Call from C++”);
> runOnUiThread(new Runnable() {
> public void run() {
> // Do nothing here… but crashed…
> }
> });
> }
> The message is print in logcat BUT app exited suddenly. I just want to call some method which must be called in Android UI thread.
> What should i do?
>
As I known , JNI method should be static , so you should change onCallFromCpp to static , after you change it , you should do another thing : give a activity to that Java class , because runOnUiThread is a method of Activity!
Can you call a non-static method within a static area? runOnUiThread is not a static method!
C Zhang wrote:
> 5 Jan wrote:
> > Hi, I want to call the java method from c++ level, so I use jni way by JNIHelper.
> >
> > In my Java class, there is a method like:
> >
> > private void onCallFromCpp() {
> > Log.d(“###”, “Call from C++”);
> > }
> >
> > this code is work good and i can see the message is print in logcat.
> >
> > but i changed the method like:
> >
> > private void onCallFromCpp() {
> > Log.d(“###”, “Call from C++”);
> > runOnUiThread(new Runnable() {
> > public void run() {
> > // Do nothing here… but crashed…
> > }
> > });
> > }
> > The message is print in logcat BUT app exited suddenly. I just want to call some method which must be called in Android UI thread.
> > What should i do?
>
> As I known , JNI method should be static , so you should change onCallFromCpp to static , after you change it , you should do another thing : give a activity to that Java class , because runOnUiThread is a method of Activity!
>
Can you call a non-static method within a static area? runOnUiThread is not a static method!
you can give a reference of activity to your JNIHelper , than you can call runOnUiThread by activity.runOnUiThread!