2013-06-01 59 views
0

嗨,我是Java SE開發新手。我試圖做一個7次嘗試的猜謎遊戲,這裏是我的不完整(應該有錯誤)。每當我試圖調試任何行消息「淨豆沒有變量顯示,因爲沒有當前線程」顯示。請給我解決方案如何擺脫這條消息,我在我的代碼中犯了什麼錯誤和什麼都可以code.Here的可能的改進是代碼:沒有變量顯示,因爲沒有當前線程

import java.util.Random; 
import java.util.*; 

public class JavaApplication3 { 

    public static void main(String[] args) { 
     ///////////////////part1 random number generation///////////////////////////////////// 
     int rnd = (int) (Math.random() * 5) + 1;//so that the position can be started after 0 
     System.out.println("Welcome to the Random Number guess Game!\n"); 
     /////////////////////////part 2 guess it is if that number//////////////////////////// 

     int number, attempt = 0; 
     Scanner sc = new Scanner(System.in);///////create scanner object 
     System.out.print("what did you guess?:"); 
     number = sc.nextInt(); 
     System.out.println("you guessed:" + number); 

     do { 
      if (number > rnd || number < rnd) { 
       System.out.println("Guess is incorrect"); 
      } 
      // System.out.println("generated number was:"+rnd); 
      System.out.println("generated number was not right"); 
      System.out.println("try again"); 
      attempt++; 
     } while (number != rnd && attempt < 7); 

     if (number == rnd) { 
      System.out.println("Guess is correct"); 
     } else { 
      System.out.println("Incorrect 7 attempts"); 
     } 
    } 
} 
+0

只是爲了確保,當程序因打斷點而停止時,您仍然看到此消息?如果程序當前正在執行(例如,未被調試器暫停),則無法檢查變量。 – Patashu

回答

1

確保你已經把斷點在方法的開始和您使用在線調試做這一行:

F7 - 進入 - 執行每個源代碼行,如果它有方法調用,並且源代碼可用,則指針移動到該方法並執行它。否則指針將移動到文件中的下一行。

通過斷點或通過在調試過程中按暫停來暫停代碼執行時,可以看到變量。然後,您可能還必須從左側的線程列表中選擇程序的主線程。此時,變量應該顯示出來。

+0

好吧,我解決了這個問題,通過給予第一個輸入,然後在每個斷點啓動調試。然後我沒有意識到,如果我不提供輸入斷點不會開始work.THANK你爲了明智的信息! –

+0

如何做同樣的事情,但沒有F7?我有幾個矩陣循環,不能按F7 180,000次,但需要知道矩陣崩潰時的變量。 – Cornelius

相關問題