如何退出扫描器类以执行循环的其余部分?
我正在访问一个扫描仪,它可以帮助从 RFID 读取器检索 RFID 标签。我尝试在我的 Scanner.next();
周围使用循环,但这不会做任何事情。我认为一旦我的扫描仪访问了 RFID 读取器的方法,它就会永久保留在那里。有没有办法退出 RFID 方法,然后执行循环的其余部分?
//The beginning of the loop
while (!doneYet) {
//Just a set boolean variable that I try to use later
Inter = false;
//A question class that I created, obtains and displays a random question
Test = Work.randomQuestion();
Test.display();
//This is where my problems seem to start, this is the RFID Readers Method.
rfid.addTagGainListener(new TagGainListener() {
public void tagGained(TagGainEvent oe) {
Temp = oe.getValue();
if (Test.getRFIDTag().equals(Temp)) {
System.out.println("You are Correct");
count++;
System.out.println(count);
Inter = true;
System.out.println("out");
/*
* try { System.in.close(); } catch (IOException e) {
* TODO Auto-generated catch block e.printStackTrace();
* }
*/
} else if (!Test.getRFIDTag().equals(Temp)) {
System.out.println("Sorry, you are wrong");
}
return;
}
});
// Before the RFID Opens though, this code is initiated
rfid.openAny();
rfid.waitForAttachment(1000);
sc = new Scanner(System.in);
//This is where I attempted to control the RFID Reader, but this doesn't work
if(!Inter){
sc.next();
}
//How I attempt to end the initial while loop
if(count>10){
doneYet = true;
}
}
预先感谢您的所有帮助。
I am accessing a Scanner that helps retrieve RFID Tags from an RFID Reader. I tried using a loop around my Scanner.next();
but that wouldn't do anything. I think that once my Scanner accesses the RFID Reader's method, that it just permanently stays in there. Is there any way to exit the method for the RFID and then perform the rest of my loop?
//The beginning of the loop
while (!doneYet) {
//Just a set boolean variable that I try to use later
Inter = false;
//A question class that I created, obtains and displays a random question
Test = Work.randomQuestion();
Test.display();
//This is where my problems seem to start, this is the RFID Readers Method.
rfid.addTagGainListener(new TagGainListener() {
public void tagGained(TagGainEvent oe) {
Temp = oe.getValue();
if (Test.getRFIDTag().equals(Temp)) {
System.out.println("You are Correct");
count++;
System.out.println(count);
Inter = true;
System.out.println("out");
/*
* try { System.in.close(); } catch (IOException e) {
* TODO Auto-generated catch block e.printStackTrace();
* }
*/
} else if (!Test.getRFIDTag().equals(Temp)) {
System.out.println("Sorry, you are wrong");
}
return;
}
});
// Before the RFID Opens though, this code is initiated
rfid.openAny();
rfid.waitForAttachment(1000);
sc = new Scanner(System.in);
//This is where I attempted to control the RFID Reader, but this doesn't work
if(!Inter){
sc.next();
}
//How I attempt to end the initial while loop
if(count>10){
doneYet = true;
}
}
Thanks in advance for all of the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的扫描仪实际上不执行任何操作。
sc.next()
只是跳过初始空格,并返回第一个非空格字符的字符串;但它只是丢弃该字符串,从不(例如)将其传递给 rfid。据我所知,没有任何东西会触发rfid
的TagGainListener
。 (无论如何,为什么要为每次循环添加一个新的TagGainListener
?您肯定只需要一个侦听器?)Your scanner doesn't actually do anything.
sc.next()
just skips initial whitespace, and returns the first string of non-whitespace characters; but it just discards that string, never (for example) passing it torfid
. As far as I can see, nothing ever triggersrfid
'sTagGainListener
. (And why do you add a newTagGainListener
for each pass through the loop, anyway? Surely you only need one listener?)