Its giving three errors;
1)non-static method initCheck() cannot be referenced from static context (line 24)
2)non-static method getHostName() cannot be referenced from static context (line 36)
3)incompatible types:
found:java.lang.string
required: java.lang.inetAddress (line 36)
The second thing I'm not getting is getByName("72.14.203.106"), I thought it would return Host name, but it's giving me some irksome values like "tx-in-f106.1e100.net"
So what's this basically doing ??
Hope to see your help soon.
Regards!
When you declare something as static it means that that 'stuff' belongs to the class itself and not to the objects generated by that class. You don't need (should not) to create an object to call an static method or access and static field (java.lang.Math.* methods are a good example of this).
Any other non-static thing should be accessed from an object (Object a a= new Thing(); a.method().
This means that you cannot combine static and non-static things so easily. When main is executed is in a static context, so you cannot call a non static method (inetCheck) since it needs to be called from an object.
So you have 2 options.
Remove your code from main and put it in a non static context (a contructor por example) or modify inetCheck to be static.
I hope I'm getting you correctly..
OKay I'm making inetCheck() as static or making some constructor, but what about getHostName() which is a non static method and I am unable to call to it both from the main(static method) and the inetCheck()(non-static) ??
I have read about static a lot, but still need something about it
Well if I make inetCheck static, then I dont even need to make this method as main is already an static one.
What the problem is that I have to include the getHostName() which is a nonstatic method into my program.
I'm having a similar problem, but my methods are EJB methods and I'm trying to call them from a jsf-managed bean. How should I reference the EJB business methods from within the JSF managed-bean ?
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Previous Thread in Java Forum Timeline:Print problem