当我向RFID扫描仪询问它的最后一个标签时,为什么会出现错误

时间:2016-11-22 20:09:55

标签: java runtime-error rfid

对于学校的项目,我必须使用多个小部件。我创建了一个类来打开一个管理器,扫描连接的phidgets并根据phidget的类型初始化他们的监听器。其中一个小部件是RFID扫描仪。现在来测试这个phidget我做了这个初始化方法(缩短了代码,因为创建了几个额外的监听器,但是没有创建错误)

public void initRFIDPhidget(RFIDPhidget rfid, int serialNumber){
    try {
        rfid.open(serialNumber);
        rfid.waitForAttachment();
        rfid.setAntennaOn(true);
        rfid.setLEDOn(false);
    } catch (PhidgetException ex) {
        Logger.getLogger(PhidgetMain.class.getName()).log(Level.SEVERE, null, ex);
    }
    rfid.addTagGainListener(new TagGainListener(){
        public void tagGained(TagGainEvent tge) {
            try {
                System.out.println(Boolean.toString(rfid.getTagStatus()));
                if(rfid.getTagStatus())
                    System.out.println((rfid.getLastTag())); //  <--- This line
                rfid.setLEDOn(true);
            } catch (PhidgetException ex) {
                Logger.getLogger(PhidgetMain.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}

正如您所看到的,有一条线给我一些问题。每当我要求getLastTag()方法时,它都会给我一个巨大的运行时错误。奇怪的是,这只发生在我用我的标签远离phidget开始我的程序时。如果我在初始化时将标签放在RFID扫描仪上,它就能完美运行。

你们有什么想法为什么会这样?

编辑:正如我所说的那样,我正在添加其余的代码和完整的错误消息

 //test variable
public static final String TEST_TAG_ID = "1e00acf9d4";

//used variables
private Manager phidgetMgr;
private Vector phidgetVec;

public static void main(String[] args){
    new PhidgetMain();
    //Initialize other programs in different threads here
}

public PhidgetMain(){
    try {
        phidgetMgr = new Manager();
        phidgetMgr.open();
        System.out.println("MANAGER OPENED\nWAITING FOR PHIDGETS TO CONNECT...");

        //Give phidgets time to connect
        Thread.sleep(1000);

        //Iterate through phidgets and initialize them
        System.out.println("OPENING PHIDGETS");
        phidgetVec = phidgetMgr.getPhidgets();
        for(int i = 0; i<phidgetVec.size(); i++){
            System.out.println("OPENING PHIDGET NUMBER " + (i+1));
            System.out.println("PHIDGET ID CODE: "+((Phidget)phidgetVec.get(i)).getDeviceID()); //Number identical for the type of phidget
            System.out.println("PHIDGET SERIAL NUMBER: "+((Phidget)phidgetVec.get(i)).getSerialNumber());
            try{
                if(((Phidget)phidgetVec.get(i)).getDeviceID()==Phidget.PHIDID_RFID_2OUTPUT){
                    RFIDPhidget rfid = new RFIDPhidget();
                    initRFIDPhidget(rfid,((Phidget)phidgetVec.get(i)).getSerialNumber());
                } else if(((Phidget)phidgetVec.get(i)).getDeviceID()==Phidget.PHIDID_INTERFACEKIT_8_8_8/*CONSTANTE KAN NIET KLOPPEN ZOEK DE OUTPUT TUSSEN DE CONSTANTEN IN DEZE LINK: http://www.phidgets.com/documentation/web/javadoc/ */){
                    InterfaceKitPhidget ikp = new InterfaceKitPhidget();
                    initInterfaceKitPhidget(ikp,((Phidget)phidgetVec.get(i)).getSerialNumber());
                }
            } catch(PhidgetException ex){
                System.out.println("OPENING PHIDGET NUMBER " + (i+1) + " THREW AN EXCEPTION");
            }
        }
    } catch (PhidgetException | InterruptedException ex) {
        Logger.getLogger(PhidgetMain.class.getName()).log(Level.SEVERE, null, ex);
    }
}

这是完整输出:

WAITING FOR PHIDGETS TO CONNECT...
OPENING PHIDGETS
OPENING PHIDGET NUMBER 1
PHIDGET ID CODE: 49
PHIDGET SERIAL NUMBER: 88983
RFID SCANNER OPENED
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000050fc9890, pid=12772, tid=17936
#
# JRE version: Java(TM) SE Runtime Environment (8.0_73-b02) (build 1.8.0_73-b02)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.73-b02 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# V  [jvm.dll+0x279890]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\Typhaon\Documents\NetBeansProjects\FYS\hs_err_pid12772.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
#
C:\Users\Typhaon\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 4 seconds)

0 个答案:

没有答案