how to resolve theese errors?

A

Andrea

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?=

"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
 
R

Robert Waters

Andrea said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top