How to access a variable in another class?
Here are snippets of the two classes I currently have. I want to be able to access and retrieve the value of the SNMPResponse variable from the main class. If I try to call it SNMPGet.SNMPResonse from the main class it says that a "non-static variable SNMPResponse cannot be referenced from a static context" how would I make this work?
Class 1.
// Retrieves SNMP details of a device.
publicclass SNMPGet{
public String SNMPResponse;
// Retrieves the SNMP variables based on the string OID and stringAddress
public String getSNMP(String OID, String address)throws Exception{
String stringOID = OID;//"1.3.6.1.2.1.1.5.0";
String stringAddress = address;//"10.31.9.41/161";
// Target address
Address targetAddress =new UdpAddress (stringAddress);
OID targetOID =new OID(stringOID);
...
Class 2.
// Control the flow of the program.
publicclass OIDScript{
publicstaticvoid main( String [] args )throws Exception{
String output =null;
SNMPGet snmpget =new SNMPGet();
output = snmpget.getSNMP("1.3.6.1.2.1.1.5.0","10.31.9.41/161");
System.out.println(output);
}
}
Cheers,
Mike
Message was edited by:
carlo_bauer

