2014-04-25 79 views
1

我不明白爲什麼我在幾個地方得到「錯誤找不到符號」。有人可以請解釋一下這個簡單的問題。Java - 錯誤找不到符號

  • PriceCalculator.java:18:error:can not find symbol --- private JTextFeild priceFeild1;
  • PriceCalculator.java:19:error:can not find symbol --- private JTextFeild priceFeild2;
  • PriceCalculator.java:41:error:can not find symbol --- setDefaultCloseOpperation(JFrame.EXIT_ON_CLOSE);
  • PriceCalculator.java:44:error:can not find symbol --- buildPanel();

    import javax.swing.*; 
    public class PriceCalculator extends JFrame 
    { 
    private JPanel panel;        // References the panel 
    
    private JLabel messageLabel1;      // References the whole sale label 
    private JLabel messageLabel2;      // References the markup label percentage 
    
    private JTextFeild priceFeild1;     // References the whole sale price 
    private JTextFeild priceFeild2;     // Referencts the markup label percentage 
    
    private JButton calcButton;      // References the calculator button 
    
    private final int WINDOW_WIDTH = 550;   // References the window width 
    private final int WINDOW_HEIGHT = 550;   // Referenecs the window height 
    
    /** 
    
    Constructor below 
    
    */ 
    
    public PriceCalculator() 
    { 
    // Set the window title 
    setTitle("Retail Price Calculator"); 
    
    // Set the size of the window 
    setSize(WINDOW_WIDTH, WINDOW_HEIGHT); 
    
    // Set the [x] exit button to close the program for the user 
    setDefaultCloseOpperation(JFrame.EXIT_ON_CLOSE); 
    
    // Build the panel and add it to the JFrame 
    buildPanel(); 
    
    // Add the contents to the panels frame 
    add(panel); 
    
    // Display the window here 
    setVisible(true); 
    } 
    
    
    
    
    /** 
    
    Main Method Below 
    
    */ 
    
    public static void main(String[] args) 
    { 
    new PriceCalculator(); 
    } 
    
    } 
    
+2

猛禽的答案是完全正確的;我只是建議你使用IDE來防止你在類/方法中輸入錯誤。 –

+0

重複的http://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-compilation-error-mean –

回答

4

這是因爲你拼寫錯了(JTextFeild)。它應該是JTextField

此外,setDefaultCloseOperation代替setDefaultCloseOpperation

+2

另外,得到像Eclipse一樣的IDE。這樣一個微不足道的錯誤很容易被智能代碼編輯器發現,它也會提供如何解決它的建議(例如提供相似但拼寫正確的已知類型和方法)。你似乎正在讓自己更加困難:) – hiergiltdiestfu

0

你的拼寫錯誤:

JTextFeild,而不是JTextField

setDefaultCloseOpperation(JFrame.EXIT_ON_CLOSE); 而不是setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);您在使用。