JOptionPane方法未找到

时间:2015-04-22 17:07:15

标签: java swing

这是我的代码:

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

2 个答案:

答案 0 :(得分:1)

编译器基本上说的是以下内容。

  • onActivityCreated(Bundle课程中没有showInputdialog方法。它被命名为JOptionPane(请注意首都' D')。它位于您的计划的第23行。
  • 它(编译器)找不到showInputDialog类,它被称为JOption。这可以在您的计划的第34行找到。

此外,您正在静默地吞噬代码中的异常,这是一种非常糟糕的做法。尽量避免这种情况。

希望这有帮助。

答案 1 :(得分:0)

拼写和案例计数:

showInputdialog!= showInputDialog

请注意,后者是调用方法的正确方法(Dialog为大写)