Jpype: "Can't start the AWT because Java was started on the first thread." -
i'm using jpype use java class python script. java class involves use of awt library: , seems problem.
this python script:
import jpype import os.path import threading jarpath = os.path.join(os.path.abspath('.'), 'build/jar') target=jpype.startjvm(jpype.getdefaultjvmpath(), "-djava.ext.dirs=%s" % jarpath) capture = jpype.jclass('capture') # capture class, contained in ./ folder t = capture(50,354,90,90,130,650,"num",36); # create instance jpype.shutdownjvm() so i'm trying instantiate class, , exit. java class. i'm reporting code causing error:
class capture { public capture(int x, int y, int width, int height, int mousenextx, int mousenexty, final string fnamestart, final int countmax) { //... images = new arraylist<bufferedimage>(); getimages(fnamestart,countmax); //this problem } // reference getimages() method: public void getimages(string fname, int countmax) { images.clear(); for(int i=0; i<=countmax; i++) { try { bufferedimage img = imageio.read(new file(fname+i+".bmp")); images.add(img); } catch(ioexception e) { images.add(null); } } } } this code, when running python script, raise me following error:
jpype._jexception.virtualmachineerrorpyraisable: java.lang.internalerror: can't start awt because java started on first thread. make sure startonfirstthread not specified in application's info.plist or on command line long story short, known problem: eclipse had "its own version", solved. unfortunately no 1 spoke problem relating jpype.
i tried these solutions, didn't worked:
in python script, launching thread before starting jvm. , starting jvm in thread.
-
in python script, starting jvm parameter
-xstartonfirstthread:target=jpype.startjvm(jpype.getdefaultjvmpath(), "-xstartonfirstthread -djava.ext.dirs=%s" % jarpath) -
in java code: using awt method
invokelater, in constructor:java.awt.eventqueue.invokelater(new runnable() { public void run() { images = new arraylist<bufferedimage>(); getimages(fnamestart,countmax); } });
i don't know do, hoping me. thank you,
giovanni
use parameter:
jpype.startjvm(jpype.getdefaultjvmpath(), '-djava.awt.headless=true')
Comments
Post a Comment