This is the mail archive of the
java-discuss@sourceware.cygnus.com
mailing list for the Java project.
Strange behaviour with vectors/arrays
- To: java discuss <java-discuss@sourceware.cygnus.com>
- Subject: Strange behaviour with vectors/arrays
- From: Simon Gornall <simon@unique-id.com>
- Date: Wed, 30 Jun 1999 13:37:40 +0100
- Organization: Unqiue ID Software Ltd
Here's a code fragment (more or less verbatim from natFile.cc) which
works fine on one machine but fails on another. Both machines have
the same version of Linux, the same egcs version, and the same libgcj
// -------------------------------------------------------------------
// Create a vector for storing these results
// -------------------------------------------------------------------
jstring canon = JvNewStringUTF("dummy");
java::util::Vector *vec = new java::util::Vector ();
for (int i=0; i<count; i++)
{
jstring result = NULL;
if (row[i] != NULL)
{
cerr << "Adding '" << row[i] << "'\n";
jstring result = JvNewStringUTF(row[i]);
}
vec->addElement(result);
}
// -------------------------------------------------------------------
// Re-express the vector as an array and return
// -------------------------------------------------------------------
jobjectArray ret = JvNewObjectArray (vec->size(),
canon->getClass(),
NULL);
vec->copyInto(ret);
return reinterpret_cast<jstringArray> (ret);
// -------------------------------------------------------------------
// Function end
// -------------------------------------------------------------------
I call the function (which returns jstringArray) using java code looking
like:
String[] results = _mysql.getRow();
The row[i] values always print out ok, so the C++ is working fine.
The array has the right length, so I assume the vector is adding
elements properly...
Unfortunately, on one machine, the following code just prints [null]
for each of the results[] entries. On another machine it's fine.
for (int j=0; j<results.length; j++)
System.err.print("["+results[j] + "] " );
System.err.println("");
Presumably this means there is *some* difference between my setups but I'm
damned if I can find it... Anyone had any similar experiences ?
Thanks for any help,
ATB,
Simon.