2011-12-03 2 views
0

私は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; 
     } 
    } 

ご協力いただきありがとうございます。

+0

このコードがコンパイルされるのは本当に驚きです。あなたの 'count'は' final'に強制されなければなりません。その場合 '++'は許されません。 – Gray

答えて

0

スキャナは実際に何もしません。 sc.next()は最初の空白をスキップし、最初の空白以外の文字列を返します。その文字列を捨てるだけです(たとえば)rfidに渡すことはありません。私が見る限り、rfidTagGainListenerを誘発するものはありません。 (なぜ、ループを通過するたびに新しいTagGainListenerを追加するのですか?確かに1つのリスナーのみ必要ですか?)

関連する問題