Java:"AWT-EventQueue-3"中的异常



我正在Oracle工作,并试图将表单从6i移动到11g。我正试图使用jssc从称重机连接并获得重量(数据)。我正面临一些问题。

代码如下:

package oracle.forms.demo;
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
import jssc.SerialPort;
import jssc.SerialPortException;
import oracle.forms.handler.IHandler;
import oracle.forms.ui.CustomEvent;
import oracle.forms.properties.ID;
import oracle.forms.ui.VBean;
public class Comm extends VBean{
    static IHandler mHandler;
    static SerialPort serialPort;
    int com_port;
    int baud_rate;
    int scale_parity;
    int scale_databits;
    int scale_stop_bits;
    boolean scale_dtr;
    boolean scale_rts;
    String scale_command;
    int scale_time_out;
    //protected static final ID SETPROPS = ID.registerProperty("SETPROPS");
    protected static final ID GETDATA = ID.registerProperty("GETDATA");
    protected static final ID SETPORT = ID.registerProperty("SETPORT");
    protected static final ID SETBAUD = ID.registerProperty("SETBAUD"); 
    protected static final ID SETPARITY = ID.registerProperty("SETPARITY"); 
    protected static final ID SETDATABITS = ID.registerProperty("SETDATABITS"); 
    protected static final ID SETSTOPBITS = ID.registerProperty("SETSTOPBITS"); 
    protected static final ID SETDTR = ID.registerProperty("SETDTR"); 
    protected static final ID SETRTS = ID.registerProperty("SETRTS"); 
    protected static final ID SETCOMMAND = ID.registerProperty("SETCOMMAND");
    protected static final ID SETTIMEOUT = ID.registerProperty("SETTIMEOUT"); 
    // events you can raise
    protected static final ID EVT_01 = ID.registerProperty("EVT_01");
    public Comm()
    {
        super();
    }
    public void init(IHandler handler)
    {
        super.init(handler);
        mHandler = handler;
        // put your initialisation instructions here
    }
    /**
     * Get the properties of the bean
     **/
    public boolean setProperty(ID property, Object value)
    {   
        if (property == SETPORT)
        {   
            com_port = Integer.parseInt((String)value);
                        System.out.println("In RSET_PORT");
            return true;
        }
        else if(property == SETBAUD)
        {
            baud_rate = Integer.parseInt((String)value);
                        System.out.println("In SET_BAUD");
            return true;
        }
        else if (property == SETPARITY)
        {             
            scale_parity = Integer.parseInt((String)value);
            return true;
        }
        else if (property == SETDATABITS)
        {             
            scale_parity = Integer.parseInt((String)value);
                        System.out.println("In DATA_BITS");
            return true;
        }
        else if (property == SETSTOPBITS)
        {       
            scale_stop_bits = Integer.parseInt((String)value);
                        System.out.println("In SET_STOP_BITS");
            return true;
        }
        else if(property == SETDTR)
        {
            if (Integer.parseInt((String)value) == 0)
            {
                scale_dtr = false;
                                System.out.println("In DTR");
                return true;
            }
            else
            {
                scale_dtr = true;
                                System.out.println("In DTR");
                return true;
            }
        }
        else if(property == SETRTS)
        {
            if(Integer.parseInt((String)value) == 0)
            {
                scale_rts = false;
                                System.out.println("In RTS");
                return true;
            }
            else
            {
                scale_rts = true; 
                                System.out.println("In RTS");
                return true;
            }
        }
        else if(property == SETCOMMAND)
        {
            scale_command = (String)value;
                        System.out.println("In SET_COMMAND");
            return true;
        }
        else if(property == SETTIMEOUT)
        {
            scale_time_out = Integer.parseInt((String)value);
                        System.out.println("In SET_TIME_OUT");
            return true;        
        }
        else // default behaviour
        {
            return super.setProperty(property, value);
        }
    }
    /**
     * Get the properties of the bean
     **/
    public Object getProperty(ID property)
    {
        if(property == GETDATA){  
            System.out.println("Running comProp");
            System.out.println("com_port: " + com_port);
            System.out.println("baud_rate: " + baud_rate);
            System.out.println("scale_parity: " + scale_parity);
            System.out.println("scale_databits: " + scale_databits);
            System.out.println("scale_stop_bits: " + scale_stop_bits);
            System.out.println("scale_dtr: " + scale_dtr);
            System.out.println("scale_rts: " + scale_rts);
            System.out.println("scale_command: " + scale_command);
            System.out.println("scale_time_out: " + scale_time_out);
            System.out.println("Serialport");
            SerialPort serialPort = new SerialPort("COM1");
            boolean leave = false;
            int i = 1;
            String str = null;
                        System.out.println("while loop");
            //In the constructor pass the name of the port with which we work
            while(leave == false){
                try
                {
                    serialPort.openPort();
                    serialPort.setParams(baud_rate,scale_parity,scale_databits,scale_stop_bits, scale_rts, scale_dtr);
                    serialPort.writeString(scale_command + (char)13 + (char)10);
                    str = serialPort.readString(i,scale_time_out );
                    i = i + 1;
                    serialPort.closePort();
                }
                catch (Exception exc) 
                {
                    //System.out.println(exc);
                    leave = true;
                    //System.out.println("Length: " + (i-1));
                    System.out.println("String: "+ str);
                }

            }
            return str;
        }
        else 
        {
            return super.getProperty(property);    
        }
    }
    public void dispatch_event( ID id )
    {
        CustomEvent ce = new CustomEvent(mHandler, id);
        dispatchCustomEvent(ce);
    }
}

这里是错误信息。

Exception in thread "AWT-EventQueue-3" java.lang.ExceptionInInitializerError
    at jssc.SerialPort.<init>(SerialPort.java:120)
    at oracle.forms.demo.Comm.getProperty(Comm.java:151)
    at oracle.forms.handler.UICommon.onGet(Unknown Source)
    at oracle.forms.engine.Runform.onGetHandler(Unknown Source)
    at oracle.forms.engine.Runform.processMessage(Unknown Source)
    at oracle.forms.engine.Runform.processSet(Unknown Source)
    at oracle.forms.engine.Runform.onMessageReal(Unknown Source)
    at oracle.forms.engine.Runform.onMessage(Unknown Source)
    at oracle.forms.engine.Runform.processEventEnd(Unknown Source)
    at oracle.ewt.lwAWT.LWComponent.redispatchEvent(Unknown Source)
    at oracle.ewt.lwAWT.LWComponent.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied (java.util.PropertyPermission user.home read)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
    at java.lang.System.getProperty(Unknown Source)
    at jssc.SerialNativeInterface.<clinit>(SerialNativeInterface.java:85)
    ... 26 more

幸好我解决了。

是一个文件错误。我们需要在代码文件所在的位置包含jssc文件。

谢谢。

相关内容

  • 没有找到相关文章

最新更新