gpt4 book ai didi

java - InetAddress.getByName 无法解析为类型

转载 作者:行者123 更新时间:2023-12-01 06:51:35 25 4
gpt4 key购买 nike

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

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.");
}

}
}

最佳答案

摆脱"new"。这是一个静态方法。

关于java - InetAddress.getByName 无法解析为类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25228711/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com