2015-04-22 63 views
0

這裏是我的代碼:的JOptionPane找不到方法

import javax.swing.JOptionPane; 
import javax.swing.*; 
import java.net.*; 
import java.*; 

public class icmp 
{ 
    public static void main(String args[]) 
    { 
     try 
     { 
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 
     } 
     catch (Exception e) 
     {} 

     int time = 0; 

     while (true) 
     { 
      time = Integer.parseInt(JOptionPane.showInputDialog("enter a time")); 
      break; 
     } 

     time = time * 1000; 
     String str = JOptionPane.showInputdialog("Enter the IP address"); 

     try 
     { 
      InetAddress addr = InetAddress.getByName(str); 
      boolean test = addr.isReachable(time); 

      if (test) 
      { 
       JOptionPane.showMessageDialog(null, str + " Host isConnected", "Alert", JOptionPane.ERROR_MESSAGE); 
      } 
      else 
      { 
       JOption.showMessageDialog(null, str + "Host is not Connected", "Alert", JOption.ERROR_MESSAGE); 
      } 
     } 
     catch (Exception e) 
     {} 
    } 
} 

這裏是我得到的錯誤:

icmp.java:23: error: cannot find symbol 
     String str = JOptionPane.showInputdialog("Enter the IP address"); 
           ^
    symbol: method showInputdialog(String) 
    location: class JOptionPane 
icmp.java:34: error: cannot find symbol 
       JOption.showMessageDialog(null,str+ "Host is not Connected","Alert",JOption.ERROR_MESSAGE); 
                        ^
    symbol: variable JOption 
    location: class icmp 
icmp.java:34: error: cannot find symbol 
       JOption.showMessageDialog(null,str+ "Host is not Connected","Alert",JOption.ERROR_MESSAGE); 
       ^
    symbol: variable JOption 
    location: class icmp 
3 errors 

回答

0

拼寫和案例數:

showInputdialog = showInputDialog

請注意,後者是打電話給我的正確方法thod(對話框爲大寫)

1

編譯器基本上說的是以下內容。

  • JOptionPane類中沒有showInputdialog方法。它的名字是showInputDialog(注意首都'D')。它位於程序的第23行。
  • 它(編譯器)找不到JOption類,它被稱爲JOptionPane。這在你的程序的第34行中找到。

另外,您正在默默吞下代碼中的異常,這是一種非常糟糕的做法。儘量避免這種情況。

希望這會有所幫助。