java的非静态方法_java – 非静态方法无法从静态上下文引用

参见英文答案 >

What is the reason behind “non-static method cannot be referenced from a static context”?                                    13个

首先一些代码:

import java.util.*;

//...

class TicTacToe

{

//...

public static void main (String[]arg)

{

Random Random = new Random() ;

toerunner () ; // this leads to a path of

// methods that eventualy gets us to the rest of the code

}

//...

public void CompTurn (int type, boolean debug)

{

//...

boolean done = true ;

int a = 0 ;

while (!done)

{

a = Random.nextInt(10) ;

if (debug) { int i = 0 ; while (i<20) { System.out.print (a+", ") ; i++; }}

if (possibles[a]==1) done = true ;

}

this.board[a] = 2 ;

}

//...

} //to close the class

这是错误信息:

TicTacToe.java:85: non-static method nextInt(int) cannot be referenced from a static context

a = Random.nextInt(10) ;

^

究竟出了什么问题?那个错误消息“非静态方法不能从静态上下文引用”是什么意思?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值