What does "can't get it to work" mean?

Is mActivity really a reference to the correct activity?
Does is successfully find the method, or take the 'return false;'
exit? (Which is rather odd in a void method!)
Does it crash?
Does it call the Java code, but with a corrupted message?

If it's that last, I'd look for the usual C++ headaches, such as using
a std::string() that has been destructed by the time you use it.

If it's crashing: Where is it crashing? How is mJNIEnv declared and
assigned?

Have you stepped through it in a debugger? I don't know hard that is
to do on a device (or emulator) with the NDK, but you could certainly
write a little test app on your PC and test the C++ side there. You'd
have to substitute on the Java side, of course; a simple
System.out.println("Success: " + pMsg); would suffice.

If none of that helps, I'd suggest asking the question in a list that
relates to the NDK rather than the SDK. You'd find a larger pool of
people able to understand and answer your questions on the topic.

On Dec 14, 10:30 am, Floof <[email protected]> wrote:
> Hi list !
>
> I'm having this problem:
>
> In my application, I use a GLSurfaceView for 3D rendering. The real
> rendering is done by calling native methods, coded in C++.
>
> Once in a while (upon user clicks on 3D scene objects) the native
> rendering engine should be able to call Java methods (through JNI)
> that display a dialog box.
>
> I can't get it to work, that's driving me crazy.
>
> Here is the native method:
>
> [CODE]
> void MyCPlusPlusClass::showDialog(const std::string& pMsg)
> {
>     jclass lClass = mJNIEnv->GetObjectClass(mActivity);
>     if (!lClass)
>     {
>         return false;
>     }
>     jmethodID lMethId = mJNIEnv->GetMethodID(lClass,
> "showMessageDialog", "(Ljava/lang/String;)V");
>     if (!lMethId)
>     {
>         return false;
>     }
>     jstring lJavaString = mJNIEnv->NewStringUTF(pMessage.c_str());
>     mJNIEnv->CallVoidMethod(mActivity, lMethId, lJavaString);}
>
> [/CODE]
>
> Then, the method showMessageDialog, coded in Java, in my activity:
>
> [CODE]
> public void showMessageDialog(String pMsg)
> {
>     Log.i("Vg", "Create dialog with message " + pMsg);
>     Log.i("Vg", "Show dialog");
>     runOnUiThread(
>         new Runnable () {
>             public void run () {
>                 AlertDialog.Builder lAlertBox = new
> AlertDialog.Builder(this);
>                 TextView lTextView = new TextView(MyActivity.this);
>                 lTextView.setText(mMessage);
>                 lAlertBox.setView(lTextView);
>                 lAlertBox.setNeutralButton("Ok", MyActivity.this);
>                 lAlertBox.setOnCancelListener(MyActivity.this);
>                 lAlertBox.show();
>             }
>         }
>     );}
>
> [/CODE]
>
> I thought this would work, but it doesn't. What am I doing wrong ?
>
> Thanks
> Florent.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to