how to resolve theese errors?

Discussion in 'Java' started by Andrea, Sep 20, 2005.

  1. Andrea

    Andrea Guest

    This is the code:
    class Ipktgen {


    public native int Pktgen(int ttl, long d_ip, byte[] payload);
    int ttl = this.ttl;
    long d_ip = this.d_ip;
    byte[] payload = this.payload;
    static {System.loadLibrary("Lpktgen");}

    public static void main(String[] args) {

    Ipktgen pkt = new Ipktgen();
    int result = pkt.Pktgen(ttl, d_ip, payload);

    }
    }

    Theese are compiler's errors:

    Ipktgen.java:13: non-static variable ttl cannot be referenced from a static
    context
    int result = pkt.Pktgen(ttl, d_ip, payload);
                            ^
    Ipktgen.java:13: non-static variable d_ip cannot be referenced from a static
    context
    int result = pkt.Pktgen(ttl, d_ip, payload);
                                 ^
    Ipktgen.java:13: non-static variable payload cannot be referenced from a
    static context
    int result = pkt.Pktgen(ttl, d_ip, payload);
     
    Andrea, Sep 20, 2005
    #1
    1. Advertising

  2. "non-static variable ttl cannot be referenced from a static context"

    This means that the variables called from a static function must be
    static too.

    Karl

    Andrea wrote:
    > This is the code:
    > class Ipktgen {
    >
    >
    > public native int Pktgen(int ttl, long d_ip, byte[] payload);
    > int ttl = this.ttl;
    > long d_ip = this.d_ip;
    > byte[] payload = this.payload;
    > static {System.loadLibrary("Lpktgen");}
    >
    > public static void main(String[] args) {
    >
    > Ipktgen pkt = new Ipktgen();
    > int result = pkt.Pktgen(ttl, d_ip, payload);
    >
    > }
    > }
    >
    > Theese are compiler's errors:
    >
    > Ipktgen.java:13: non-static variable ttl cannot be referenced from a static
    > context
    > int result = pkt.Pktgen(ttl, d_ip, payload);
    > ^
    > Ipktgen.java:13: non-static variable d_ip cannot be referenced from a static
    > context
    > int result = pkt.Pktgen(ttl, d_ip, payload);
    > ^
    > Ipktgen.java:13: non-static variable payload cannot be referenced from a
    > static context
    > int result = pkt.Pktgen(ttl, d_ip, payload);
     
    =?ISO-8859-15?Q?Karl_=D8ie?=, Sep 20, 2005
    #2
    1. Advertising

  3. "Andrea" <> wrote in message
    news:z8UXe.37795$...
    > This is the code:
    > class Ipktgen {
    >
    >
    > public native int Pktgen(int ttl, long d_ip, byte[] payload);
    > int ttl = this.ttl;
    > long d_ip = this.d_ip;
    > byte[] payload = this.payload;
    > static {System.loadLibrary("Lpktgen");}
    >
    > public static void main(String[] args) {
    >
    > Ipktgen pkt = new Ipktgen();
    > int result = pkt.Pktgen(ttl, d_ip, payload);

    ^ ^ ^
    These three are instance variables of the Ipktgen class.

    try:
    int result = pkt.Pktgen(pkt.ttl, pkt.d_ip, pkt.payload);

    Bob
     
    Robert Waters, Sep 20, 2005
    #3
  4. Andrea

    Roedy Green Guest

    Roedy Green, Sep 20, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,009
    Mark Goldin
    Jan 17, 2004
  2. Jody
    Replies:
    1
    Views:
    695
    Andrew Thompson
    Nov 11, 2004
  3. Jody
    Replies:
    1
    Views:
    1,371
    Andrew Thompson
    Nov 15, 2004
  4. Replies:
    1
    Views:
    10,314
  5. James M. Lawrence
    Replies:
    0
    Views:
    100
    James M. Lawrence
    Mar 23, 2009
Loading...

Share This Page