JNI: calling java

From: Thomas Smith (thomas.smith_at_cox.net)
Date: 10/08/04


Date: Fri, 8 Oct 2004 16:31:27 -0400

I am having a bear of a time making a return call from C++ back to a java
Object.
I keep getting a NoSuchMethod Exception. Unfortunately, I see different
possible signatures in several different articles.
Can anyone out there give me a definitive answer on this?

here is the java Code:

public class CPlusPlusTest {

 static{
  System.loadLibrary("JNITest");
   }
  public void callMe(){
  System.out.println("java was called");
 }
 public native void doHello();

 public static void main(String[] args) {

  new CPlusPlusTest().doHello();

 }
}

and here is the C++ code:

VOID Java_com_ts_jni_play_CPlusPlusTest_doHello
  (JNIEnv * env, jobject jObj){
    printf("do hello called natively");
    jclass cls=env->GetObjectClass(jObj);
    if(cls==0) printf("class not found");
  }

-- 
Thomas W. Smith
Senior Engineer 


Relevant Pages

  • Quick Question
    ... I noticed that their examples for the main method has a void return type. ... In other languages you tend to use an int return type and send either a 1 or a 0 to the operating sytem when exiting. ... I was wondering if you are meant to do this in java and if not why doesn't java return a value to operating system as is typical in other languages. ... public static void main{ ...
    (comp.lang.java.programmer)
  • Re: Question about sample Java application
    ... > private static String name; ... > public static void main{ ... In most of what I've been doing, when I have to do a Java ... application within that one .java file. ...
    (comp.lang.java.programmer)
  • Re: beginners question
    ... It must accept a String array as a parameter. ... public static void main ... When java tells you that it cannot find a method, ... requiring an applet viewer. ...
    (comp.lang.java)
  • Re: OO is not that great: many repeated codes
    ... Instances of both classes have to be able to handle the driveCarWell message - how they do handle it is implementation-dependant, and doesn't necessarily requires implementing the method in each class. ... void cookDeliciousFood() ... int average ... But it's true that Java has no support for the former and forbid the later. ...
    (comp.object)
  • Java Dialog’s from C++
    ... I want to use Java from C++. ... void CreateJavaVM(); ... AWT because Java was started on the first thread. ...
    (comp.sys.mac.programmer.codewarrior)