大家救救小弟我啊这个有关问题把小弟我整死了~
大家救救我啊~~~这个问题把我整死了~~~
[code=Java][/package test;
public class TT {
public int a;
public byte[] comm={0x7E,0x48,0x7d};
public int teset(){
a=FormTcpAndUnformTCP.formTcp(comm,3);
return a ;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(teset());
}
}
]
在a=FormTcpAndUnformTCP.formTcp(comm,3);和System.out.println(teset());报错:Cannot make a static reference to the non-static method formTcp(byte[], int) from the type FormTcpAndUnformTCP
愁死我了 怎么从根本上解决问题啊~~~
------解决方案--------------------
new TT().teset();
实例方法需要一个实例来调用。
------解决方案--------------------
方法前加个static声明就好了~~
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
static修饰符,表示属于类本身,而不用实例化该类,调用时直接通过类名.要访问的信息就可以了,比如:
类名.方法名()就可以了
当然静态方法能访问的参数也必须是属于该类的字段,所以把你声明的字段也加上static。
[code=Java][/package test;
public class TT {
public int a;
public byte[] comm={0x7E,0x48,0x7d};
public int teset(){
a=FormTcpAndUnformTCP.formTcp(comm,3);
return a ;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(teset());
}
}
]
在a=FormTcpAndUnformTCP.formTcp(comm,3);和System.out.println(teset());报错:Cannot make a static reference to the non-static method formTcp(byte[], int) from the type FormTcpAndUnformTCP
愁死我了 怎么从根本上解决问题啊~~~
------解决方案--------------------
new TT().teset();
实例方法需要一个实例来调用。
------解决方案--------------------
方法前加个static声明就好了~~
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------
static修饰符,表示属于类本身,而不用实例化该类,调用时直接通过类名.要访问的信息就可以了,比如:
类名.方法名()就可以了
当然静态方法能访问的参数也必须是属于该类的字段,所以把你声明的字段也加上static。