Java InetAddress.getByName无法解析为类型

Java InetAddress.getByName无法解析为类型,java,inetaddress,Java,Inetaddress,我试图使用InetAddress返回用户输入的网站名称的IP地址,但在语句中出现错误: InetAddress ip=新的InetAddress.getByNamesite; 显示的错误是: InetAddress.getByName cannot be resolved to a type 我的代码: import java.util.*; import java.net.*; import java.io.*; import java.net.InetAddress; public cl

我试图使用InetAddress返回用户输入的网站名称的IP地址,但在语句中出现错误: InetAddress ip=新的InetAddress.getByNamesite; 显示的错误是:

InetAddress.getByName cannot be resolved to a type
我的代码:

import java.util.*;
import java.net.*;
import java.io.*;
import java.net.InetAddress;

public class getIP {
    public static void main(String args[])throws UnknownHostException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String site;
        System.out.println("Enter the url :");
        site = br.readLine();
        try
        {
            InetAddress ip = new InetAddress.getByName(site);
        }
        catch(UnknownHostException ee)
        {
            System.out.println("Website not found.");
        }

    }
}

摆脱“新的”。这是一种静态方法

import java.util.*;
import java.net.*;    
import java.io.*;
import java.net.InetAddress;

public class getIP {
public static void main(String args[])throws UnknownHostException 
{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String site;
    System.out.println("Enter the url :");
    site = br.readLine();
    try
    {
        InetAddress ip = InetAddress.getByName(site);
    }
    catch(UnknownHostException ee)
    {
        System.out.println("Website not found.");
    }

}
}

只是一个不应该在这里的“新的”

删除方法调用前面的new,如下所示:

InetAddress ip = InetAddress.getByName(site);
投票赞成解释为什么不需要新的。