• 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

lingle

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't start the jvm from a C++ method, the source code looks like this:

#include <jni.h>
#include <string.h>
#include <stdlib.h>

#ifdef _WIN32
#define PATH_SEPARATOR ';'
#else
#define PATH_SEPARATOR ':'
#endif
int main()
{
JavaVMOption options[2];
JNIEnv *env;
JavaVM *jvm;
JavaVMInitArgs vm_args;
jint status;
jclass cls;
jmethodID mid;
jint square;
jboolean not;

options[0].optionString="-verbose:jni";
options[1].optionString = "-Djava.class.path=.";
memset(&vm_args, 0, sizeof(vm_args));
vm_args.version = JNI_VERSION_1_4;
vm_args.nOptions = 2;
vm_args.options = options;
vm_args.ignoreUnrecognized=JNI_TRUE;



status = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);

if(status<0){
fprintf(stderr,"Cann't create Java VM\n");
exit(1);
}
if (status != JNI_ERR)
{
cls = env->FindClass("Sample2");
if(cls !=0)
{ mid = env->GetStaticMethodID(cls, "intMethod", "(I)I");
if(mid !=0)
{ square = env->CallStaticIntMethod(cls, mid, 5);
printf("Result of intMethod: %d\n", square);
}
mid = env->GetStaticMethodID(cls, "booleanMethod", "(Z)Z");
if(mid !=0)
{ not = env->CallStaticBooleanMethod(cls, mid, 1);
printf("Result of booleanMethod: %d\n", not);
}
}
jvm->DestroyJavaVM();
return 0;
}
else
return -1;
}

notation:
the development tool is VC++. the method JNI_CreateJavaVM return -1, why? Thanks!
 
Oh. Hi guys! Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic