大家救救我啊~~~这个问题把我整死了~~~

Guanglew 2011-11-22 04:43:41
[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
愁死我了 怎么从根本上解决问题啊~~~
...全文
115 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
艳沐石 2011-11-22
  • 打赏
  • 举报
回复
static修饰符,表示属于类本身,而不用实例化该类,调用时直接通过类名.要访问的信息就可以了,比如:
类名.方法名()就可以了

当然静态方法能访问的参数也必须是属于该类的字段,所以把你声明的字段也加上static。


我嘞个去 2011-11-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 huntor 的回复:]
信春哥原地复活。

你未结的帖子比例有点高了
[/Quote]
信春哥,考本科!
艳沐石 2011-11-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jacky_wang_123 的回复:]

亲 您能说的具体一点吗?在哪个地方加 怎么加啊? 我刚刚学java !
[/Quote]

这样添加。
public class TT {
public static int a;
public static byte[] comm = { 0x7E, 0x48, 0x7d };

public static int teset() {
a = FormTcpAndUnformTCP.formTcp(comm, 3);
return a;
}

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(teset());
}
}
Guanglew 2011-11-22
  • 打赏
  • 举报
回复
亲 您能说的具体一点吗?在哪个地方加 怎么加啊? 我刚刚学java !~~[Quote=引用 4 楼 liuqianqian 的回复:]

引用 3 楼 creso 的回复:
方法前加个static声明就好了~~

+1
不是静态方法,需要new一个实例调用!
[/Quote]
liuqianqian 2011-11-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 creso 的回复:]
方法前加个static声明就好了~~
[/Quote]
+1
不是静态方法,需要new一个实例调用!
creso 2011-11-22
  • 打赏
  • 举报
回复
方法前加个static声明就好了~~
huntor 2011-11-22
  • 打赏
  • 举报
回复
信春哥原地复活。

你未结的帖子比例有点高了
huntor 2011-11-22
  • 打赏
  • 举报
回复
new TT().teset();

实例方法需要一个实例来调用。

23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧