当前位置: 技术问答>java相关
救命呀!
来源: 互联网 发布时间:2015-04-07
本文导语: 源程序: import java.net.*; public class NetTool {InetAddress myIPaddress=null; InetAddress myServer=null; public static void main(String args[]){ NetTool mytool; mytool=new NetTool(); System.out.println("your host IP is:"+mytool.getMYIP()); System.out....
源程序:
import java.net.*;
public class NetTool
{InetAddress myIPaddress=null;
InetAddress myServer=null;
public static void main(String args[]){
NetTool mytool;
mytool=new NetTool();
System.out.println("your host IP is:"+mytool.getMYIP());
System.out.println("The Server IP is:"+mytool.getServerIP());
}
//取得LOCALHOST的IP地址
public InetAddress getMyIP(){
try{myIPaddress=INETAddress.getLocalHost();}
catch(UnknownHostException e){}
return (myIPaddress);
}
//取得www.sina.com.cn的IP地址
public InetAddress getServerIP(){
try{myServer=InetAddress.getByName("www.sina.com.cn");}
catch(UnknownHostException e){}
return (myServer);
}
}
错误:
NetTool.java:18:cannot resolve symbol
symbol:method getMYIP()
location:class NetTool
System.out.println("your host IP is:"+mytool.getMYIP());
^
NetTool.java:23:cannot resolve symbol
symbol:variable INETAddress
location:class NetTool
try{myIPaddress=INETAddress.getLocalHost();}
^
2 errors
如果验证成功的话,马上给分,不够再开!
import java.net.*;
public class NetTool
{InetAddress myIPaddress=null;
InetAddress myServer=null;
public static void main(String args[]){
NetTool mytool;
mytool=new NetTool();
System.out.println("your host IP is:"+mytool.getMYIP());
System.out.println("The Server IP is:"+mytool.getServerIP());
}
//取得LOCALHOST的IP地址
public InetAddress getMyIP(){
try{myIPaddress=INETAddress.getLocalHost();}
catch(UnknownHostException e){}
return (myIPaddress);
}
//取得www.sina.com.cn的IP地址
public InetAddress getServerIP(){
try{myServer=InetAddress.getByName("www.sina.com.cn");}
catch(UnknownHostException e){}
return (myServer);
}
}
错误:
NetTool.java:18:cannot resolve symbol
symbol:method getMYIP()
location:class NetTool
System.out.println("your host IP is:"+mytool.getMYIP());
^
NetTool.java:23:cannot resolve symbol
symbol:variable INETAddress
location:class NetTool
try{myIPaddress=INETAddress.getLocalHost();}
^
2 errors
如果验证成功的话,马上给分,不够再开!
|
注意大小写
mytool.getMYIP()->mytool.getMyIP()
INETAddress->InetAddress
mytool.getMYIP()->mytool.getMyIP()
INETAddress->InetAddress
|
mytool.getMYIP()
is
mytool.getMyIP()
is
mytool.getMyIP()
|
java 和 c++一样,是大小写敏感的,你在写代码的时候一定要注意大小写,你怎么定义的变量和方法就应该怎么调用,错一个字母都不行!
|
类方法未找到。
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。