Winanjaya
Jan 14th, 2010, 08:24 AM
Hello All,
I am new to Java and I am learning it, I try to get the value from a function but .. it returns error:
non-static variable jTxtHostName cannot be referenced from a static context
jTxtHostName.setText(cls1.getComputerName());
public String getComputerName()
{
String ret = "";
try {
ret = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ex) {
Logger.getLogger(Class1.class.getName()).log(Level.SEVERE, null, ex);
}
return ret;
}
what I missed?
I am new to Java and I am learning it, I try to get the value from a function but .. it returns error:
non-static variable jTxtHostName cannot be referenced from a static context
jTxtHostName.setText(cls1.getComputerName());
public String getComputerName()
{
String ret = "";
try {
ret = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ex) {
Logger.getLogger(Class1.class.getName()).log(Level.SEVERE, null, ex);
}
return ret;
}
what I missed?