• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JNI Call Object Methods

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm new here, so thanks for comments and advices. I hope I hit the correct list.


Problem:
I have two classes Graph and Node.

Now I want to realize the following Java Code by Call from C++. I will not use callbacks, because later I want to write a wrapper library:

Graph g = new Graph();
Node A = g.addNode();


I do this to create the Graph Object in c++:


#include <jni.h>
#include <stdio.h>
#include <iostream>
#include "GraphTest.h"



JNIEXPORT jobject JNICALL Java_GraphTest_getGraph
(JNIEnv* env, jclass in_cls)

{

jclass jcls;
jmethodID jmid;
jobject jobj;

jcls = env->FindClass("Graph");
jmid = env->GetMethodID(jcls, "<init>","()V");
jobj = env->NewObject(jcls, jmid);

return jobj;

}

How can I realize the second Part [[Node A = g.addNode();]] in c++ now?




Many in thanks in advance
Parseval

 
Parseval Adamsberg
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved it already myself


jmethodID jmid2 = env->GetMethodID(jcls, "addNode","()LNode;");
jobject jobj2 = env->CallNonvirtualObjectMethod(jobj,jcls, jmid2, "V");


cheers
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Parse Val",

Please read your private messages regarding an important announcement.

Thank you,

Rob
 
Run away! Run away! Here, take this tiny ad with you:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic