Calling Java Method from Objective C -


i trying invoke simple helloworld java method objective c via jni.

the jni starts, findclass returns nil. no class found, therefore, can't invoke method.

please suggest.

my setup:

java class (located on desktop, compiled javac)

public class helloworld {     public static void main(string[] args) {           system.out.println("hello, world");     } } 

objective c

jnienv* jnienv; javavm* javavm;  - (void)launch {     javavmoption javavmoptions[2];     javavmoptions[0].optionstring = "-djava.awt.headless=true";      // directory path     javavmoptions[1].optionstring = "-djava.class.path=/users/me/desktop";      javavminitargs javavminitargs;     javavminitargs.version = jni_version_1_6;     javavminitargs.options = javavmoptions;     javavminitargs.noptions = 1;     javavminitargs.ignoreunrecognized  = jni_true;      int result = jni_createjavavm(&javavm, (void**)&jnienv, &javavminitargs);     nslog(@"java vm launched %i", result);     invoke_class(jnienv); }   void invoke_class(jnienv* env) {     jclass helloworldclass;     jmethodid mainmethod;     jobjectarray applicationargs;     jstring applicationarg0;      helloworldclass = (*env)->findclass(env, "helloworld");      mainmethod = (*env)->getstaticmethodid(env, helloworldclass, "main", "([ljava/lang/string;)v");      applicationargs = (*env)->newobjectarray(env, 1, (*env)->findclass(env, "java/lang/string"), null);     applicationarg0 = (*env)->newstringutf(env, "from-c-program");     (*env)->setobjectarrayelement(env, applicationargs, 0, applicationarg0);      (*env)->callstaticvoidmethod(env, helloworldclass, mainmethod, applicationargs); } 

you have javavminitargs.noptions = 1; in code vm sees first option , not class path declaration.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -