cni converting String args[]
Little-John
littlejohn@paranoici.org
Fri Dec 10 17:22:00 GMT 2004
* 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]);
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