首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

请大侠帮忙解决一个线程有关问题!小弟感激不尽

2012-01-15 
请大侠帮忙解决一个线程问题!小弟感激不尽!本人刚学java不久,在验证多线程如何在同一程序中运行时,此程序

请大侠帮忙解决一个线程问题!小弟感激不尽!
本人刚学java   不久,在验证多线程如何在同一程序中运行时,此程序不知哪里出了问题,请高手帮忙看看!谢谢你们得指点迷津!
class   Sister   extends   Thread{
  public   Sister(String   str){
      super(str);  
   
}  
  public   void   run(){
for(int   i=0;i <6;i++)
{
System.out.println(getName()+ "is   running: "+i);
try{sleep((int)(Math.random()*1000));}
        catch(InterruptedException   e){}

}

}
  System.out.println(getName()+ "is   running: "+i);
  }




 
  class   CountingThread   {
public   static   void   main(String   []args){
System.out.println( "the   siters   Janny   and   Marry   are   counting   the   threads ");
System.out.println( "who   are   the   first   to   runnig? ");
new   Sister( "Janny ").start();
new   Sister( "Marry ").start();
}

}





[解决办法]
System.out.println(getName()+ "is running: "+i);
==============================================
没在方法里边吧
[解决办法]
"System.out.println(getName()+ "is running: "+i); "怎么是个孤儿啊,而且这个i从那里读的到啊??
[解决办法]
class CountingThread 前面加个public就没有cant find main class问题了
[解决办法]
是你工具没用明白
你把这个文件在DOS里面去运行试一下
我的都好使
[解决办法]
楼主在开玩笑哦。。。在DOS里根本就编译不通过,出现下面错误!

CountingThread.java:16: <identifier> expected
System.out.println(getName()+ "is running: "+i);
^
1 error


你的第二个System语句就没有放在方法内部!

[解决办法]

class Sister extends Thread {
public Sister(String str) {
super(str);

}

public void run() {
for (int i = 0; i < 6; i++) {
System.out.println(getName() + "is running: " + i);
try {
sleep((int) (Math.random() * 1000));
} catch (InterruptedException e) {
}

System.out.println(getName() + "is running: " + i);
}

}
}

public class CountingThread {
public static void main(String[] args) {
System.out
.println( "the siters Janny and Marry are counting the threads ");
System.out.println( "who are the first to runnig? ");
new Sister( "Janny ").start();
new Sister( "Marry ").start();
}

}
[解决办法]
------------------------------------
ohuan(orckerth) ( ) 信誉:100
-------------------------------------
正解

还有保存的.java文件名要和包含main()方法的那个类的类名相同
[解决办法]
(String []args) ????????????
[解决办法]
你写错了2个地方
第一个错:


}
System.out.println(getName()+ "is running: "+i);


}
这里的这句代码不能放在类里面 只能放在类里的一个方法中.

第二个错:
class CountingThread {
public static void main(String []args){
包含 main方法的类,要放在一个声明为public而且和文件名相同的类当中.


以上两个地方就你的错误了~~

热点排行