java - Printing Inet4Address error -
i have little problem printing inet4address variable.
i got 'the operator + undefined argument type(s) string, void' exception.
i show part class:
public class command{ private inet4address a; public inet4address geta(){ return a; } public void showconf(){ system.out.println("interface a: ip: " + geta().gethostaddress()); // there problem } }
any simple solution?
the geta(){
hade null
return, try create constructor
, initialize inet4address
in solve problem:
public class command{ private string url = "google.com"; private inet4address = null; public command() { super(); try { = (inet4address) inet4address.getbyname(url); } catch (unknownhostexception e) { // todo auto-generated catch block e.printstacktrace(); } } public static void main(string[] args) { new command().showconf(); } public inet4address geta(){ return a; } public void showconf(){ system.out.println("interface a: ip: " + geta().gethostaddress()); } }
output:
interface a: ip: 64.15.126.118
Comments
Post a Comment