Results 1 to 5 of 5
  1. #1
    p.vaso is offline Member
    Join Date
    May 2012
    Posts
    3
    Rep Power
    0

    Default Promblem with host connection

    Hi to all,

    I am working in my dissertation, but unfortunately i stuck in the last part.

    I developed a java GUI (is running in Netbeans, and the standard host is localhost), in order to find the throughput of the interface.

    Now i have to adjust this. The new scenario is to choose any host and the number of the interface.

    I would appreciate any help you can give me.

  2. #2
    p.vaso is offline Member
    Join Date
    May 2012
    Posts
    3
    Rep Power
    0

    Default Re: Promblem with host connection

    the code is this:

    public static void main(String args[]) throws MIBItemNotFound, NetSNMPSendError, IllegalStateException, InterruptedException {

    NetSNMPSession sess ;
    NetSNMPAction myListener = new MyListener() ;

    String host, community;

    host = args[0] ;
    community = args[1] ;


    sess = new NetSNMPSession(host, community) ;
    sess.addListener(myListener) ;


    PDU pdu = new PDU(NetSNMP.MSG_GET) ;

    //ifInOctets
    ifInOctetsOID = new DefaultOID("IF-MIB::ifInOctets.24") ;
    pdu.addNullEntry(ifInOctetsOID) ;


    //ifOutOctets
    ifOutOctetsOID = new DefaultOID("IF-MIB::ifOutOctets.24") ;
    pdu.addNullEntry(ifOutOctetsOID) ;

    //SysUpTime
    sysUpTimeOID = new DefaultOID("SNMPv2-MIB::sysUpTime.0") ;
    pdu.addNullEntry(sysUpTimeOID) ;
    i have put the host in "arguments" as localhost and the number of interface as you can see is 24. How can I change this and I get from a jTextField the host and the number of interface?

    if I write istead of :
    host = args[0] ;
    this:
    host=jTextField1.getText();
    I had this message as it obvious:
    non-static variable jTextField1 cannot be referenced from a static context

    Any other idea or how to correct it?
    Last edited by p.vaso; 05-27-2012 at 09:57 PM.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Promblem with host connection

    cannot be referenced from a static context
    Move the code with the problem from a static method to a non-static method that is part of the instance of the class when it is created.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    p.vaso is offline Member
    Join Date
    May 2012
    Posts
    3
    Rep Power
    0

    Default Re: Promblem with host connection

    thank you for your answer Norm! if i move
    host=jTextField1.getText();
    it works but I want in main which is static to have a non static method with some way.

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default Re: Promblem with host connection

    Better to move it out of the main() method.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: 04-29-2011, 07:04 AM
  2. Replies: 7
    Last Post: 06-08-2010, 01:36 PM
  3. Help on Class promblem
    By jaicea in forum New To Java
    Replies: 8
    Last Post: 11-23-2009, 08:43 PM
  4. Replies: 0
    Last Post: 03-30-2009, 12:34 AM
  5. Replies: 0
    Last Post: 10-31-2008, 07:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •