[gdal-dev] SWIG JNI binding question with GetMetadataItem function
Jim Pendleton
jimp at ittvis.com
Wed Aug 10 19:34:53 EDT 2011
In GDAL 1.8.1 I'm attempting to call GetMetadataItem() within the
context of an Android 2.2 Java app, but I'm getting an error,
specifically
08-10 22:13:41.750: WARN/dalvikvm(546): JNI WARNING: jstring 0x40569100
points to non-string object (Check_GetStringUTFChars)
An access violation error follows this.
I've successfully opened the image and have a valid Dataset object.
I've debugged my way through the JPIPKAKDataset initialization method so
I'm pretty confident that much is working properly.
I don't know if this is a problem with the swig bindings or something
else. I hope someone's run into this one before.
My Java code is really straightforward:
public int getDecompositionLevels() {
if (gdalDataset != null)
{
String key = "JPIP_NRESOLUTIONLEVELS";
String domain = "JPIP";
return
Integer.parseInt(gdalDataset.GetMetadataItem(key, domain));
} else {
return -1;
}
}
This corresponds to the API definition found here:
http://gdal.org/java/org/gdal/gdal/MajorObject.html#GetMetadataItem(java
.lang.String, java.lang.String)
I've also tried the variant that uses a default domain string with the
same error as a result.
I'm using the gdal_wrap.cpp generated in the swig/java directory along
with corresponding gdal.jar file.
The org.gdal.gdal.MajorObject.java class defines the interface as
public String GetMetadataItem(String pszName, String pszDomain) {
return gdalJNI.MajorObject_GetMetadataItem__SWIG_0(swigCPtr, this,
pszName, pszDomain);
}
The swig interface file MajorObject.i defines this as
/*
* GetMetadataItem
*/
%apply Pointer NONNULL {const char * pszName};
const char *GetMetadataItem( const char *pszName, const char
*pszDomain = "" ) {
return GDALGetMetadataItem( self, pszName, pszDomain);
}
While the generated gdal_wrap.cpp is
SWIGINTERN char const
*GDALMajorObjectShadow_GetMetadataItem__SWIG_0(GDALMajorObjectShadow
*self,char const *pszName,char const *pszDomain=""){
return GDALGetMetadataItem( self, pszName, pszDomain);
}
I've found a thread discussing a similar issue under the android-ndk
group, but without the swig component:
http://groups.google.com/group/android-ndk/browse_thread/thread/27e83cdf
168bc0bb/db151ea4c15362c5?show_docid=db151ea4c15362c5
I infer from that discussion that either the GDAL interface definition
file needs to be tweaked or I need to use javah instead of swig.
I'm still new to all of this (including GDAL) so assume I'm missing
something blatantly obvious.
Thanks for any help,
Jim P.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110810/35f4292e/attachment.html
More information about the gdal-dev
mailing list