From: Neil H. <ne...@nk...> - 2007-10-29 11:34:15
|
It's been a while since I last dabbled with Jython (zxJDBC stuff about 6 months ago), so before I upgrade from 2.1 I thought I'd try out a "simple" project. I have a directory full of BMP graphic files that I would like to view, with the aim eventually to move my Swing viewer to reading the BMPs in as BLOBs from a database. BMP files appear to be an awkward case and the most popular way of reading them in appears via Google to be using the JAI package. Unfortunately my limited Java knowledge has struck home. Here's the initial code to turn the BMP file into a stream, Java-style: import java.io.*; import com.sun.media.jai.codec.SeekableStream; public class SeekableTest { public static void main(String[] args) { try { InputStream myimage = new FileInputStream("test.bmp"); SeekableStream ss = SeekableStream.wrapInputStream(myimage, false); // more code to follow... } catch(Exception ex) { System.out.println("Error:" +ex.getMessage()); } } } wrapInputStream() is a convenience method to construct a SeekableStream instance, which is an abstract class. Here's my first Jython attempt: import sys import java.io jarsToLoad = ["jai_core.jar", "jai_codec.jar"] for jar in jarsToLoad: sys.path.append(".\\" + jar) from com.sun.media.jai.codec import * import com.sun.media.jai.codec.SeekableStream myimage = java.io.FileInputStream("test.bmp") ss = com.sun.media.jai.codec.SeekableStream.wrapInputStream(myimage, 0) # more code to follow... When run in Jython 2.1 on Windows XP (JVM 1.5) the last line in the above code blows up with the following stack trace: Traceback (innermost last): File "SeekableTest.py", line 12, in ? java.lang.NullPointerException at java.lang.Class.isAssignableFrom(Native Method) at org.python.core.PyJavaClass.init__class__(PyJavaClass.java) at org.python.core.PyJavaClass.init(PyJavaClass.java) at org.python.core.PyJavaClass.initLazy(PyJavaClass.java) at org.python.core.PyJavaClass.initialize(PyJavaClass.java) at org.python.core.PyJavaClass.lookupGivingClass(PyJavaClass.java) at org.python.core.PyClass.lookup(PyClass.java) at org.python.core.PyJavaClass.__findattr__(PyJavaClass.java) at org.python.core.PyObject.__getattr__(PyObject.java) at org.python.core.PyObject.invoke(PyObject.java) at org.python.pycode._pyx0.f$0(SeekableTest.py:12) at org.python.pycode._pyx0.call_function(SeekableTest.py) at org.python.core.PyTableCode.call(PyTableCode.java) at org.python.core.PyCode.call(PyCode.java) at org.python.core.Py.runCode(Py.java) at org.python.core.__builtin__.execfile_flags(__builtin__.java) at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java) at org.python.util.jython.main(jython.java) java.lang.NullPointerException: java.lang.NullPointerException Is this due to the abstract class? Or does anybody have another solution for reading in BMPs? -- Neil Hughes |