cni converting String args[]

Andrew Haley aph@redhat.com
Fri Dec 10 17:52:00 GMT 2004


Little-John writes:
 > * littlejohn@paranoici.org (littlejohn@paranoici.org) ha scritto:
 > > * Andrew Haley (aph@redhat.com) ha scritto:
 > > > > arguments[i] = (char *) elements(argsElements[i]->getBytes());
 > > > 
 > > > If you want chars, you'll need an encoding -- elements returns a
 > > > jchar*. Try JvGetStringUTFRegion.
 > > 
 > > ok, I'll let you know
 > 
 > jint A::init(JArray< ::java::lang::String *> *args) {
 > 
 > int argc = 0;
 > char* arguments[argc];
 > 
 > if (args != NULL) // It's a very bad day otherwise
 > {
 > argc = args->length;
 > arguments[argc];
 > 
 > /*
 > * convert the JArray<String*>* in char**
 > * so in a way suitable for VLC_Init
 > */
 > ::java::lang::String** argsElements = elements(args);
 > 
 > for (int i = 0; i < argc; i++) {
 > ::java::lang::System::out->println(argsElements[i]->length());
 > JvGetStringUTFRegion(argsElements[i], 0,
 > argsElements[i]->length(), arguments[i]);
You need memory to put this in:
 len = JvGetStringUTFLength (argsElements[i]);
 char s[len];
 JvGetStringUTFRegion(argsElements[i], 0, argsElements[i]->length(), s);
 s[len] = 0;
 > printf("library: %s\n", arguments[i]);
 > }
 > }
 > return 0;
 > }
 > 
 > does not work. If i issue the command:
 > 
 > % A --help --helpp
 > 
 > i get
 > 6 (the length of --help)
 > library: --help (the printf)
 > 7 (the length of --helpp)
 > Exception in thread "main" java.lang.NullPointerException
 > 
 > debugging with gdb, I see a strange thing. Maybe related to the
 > gc. On the second iteration, just after the JvGetStringUTFRegion the
 > arguments array is:
 > 
 > (gdb) print arguments 
 > 1ドル = {0x0, 0x0}
 > 
 > I can understand why.
 > 
 > lj


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /