你这里的load.change(count);的这个load没有实例话,是个空对象阿。他不是着不到count而是找不到load。你可以这样改的
class Counter extends Thread{
CounReload load=new CounReload();
String name;
public static int count=0;
......
class Counter extends Thread{
CounReload load=new CounReload();
String name;
public static int count=0;
......
解决方案 »
- 一个初级问题,谢谢
- 祝贺:java学习交流 QQ群 开通 号码:19105801
- 急急急,求SQL Server 7.0 Jdbc驱动(在线等,解决后结贴)
- FILE文件问题
- 关于objectInputStream,(急在线等,再加100分)
- 写一个通讯程序出现出现错误 java.io.EOFException错误
- 空指针的问题
- 一个简单的问题,为什么JAVA运行环境弄不好,拜托!
- (急)有劳分析关于websphere的出错:与数据库相连的应用程序已达到最大数目
- 萌新求助(jdk-12.0.2)
- 怎样将所需的java自带的包(部分,如java.xml.*,)分离出来,形成一个新包
- 怎样利用JDBC连接oracle数据库?谢谢!!!
public class bean5 {
public static void main(String args[]){
new Counter("A");
new Counter("B");
new Counter("C");
new Counter("D");
try{Thread.sleep(10000);}
catch(InterruptedException e){}
}
}
class Counter extends Thread{
CounReload load;
String name;
int count=0;
Counter(String name){
this.name=name;
new Thread(this,"dfds").start();
}
public void run(){
while(true){
System.out.print(name+" ");
new CounReload().change(count++); try{Thread.sleep(100);}
catch(InterruptedException e){}
}
}
}
class CounReload{
synchronized void change(int c){
System.out.println("count: "+c);
}
}