跪求各路高手解决,代码如下:
public class Runnable1_ex implements Runnable
{
 char c;
 public Runnable1_ex(char c){ this.c=c;
 }
 public void run(){
    int k;
char ch=c;
System.out.println();
System.out.print(getName()+":");
for(k=0;k<=25;k++){
  ch=(char)(c+k);
  System.out.print(ch+"");
}
System.out.println(getName()+"end!");
 }
 public static void main(String args[]){
   Runnable1_ex ru1=new Runnable1_ex('A');
   Runnable1_ex ru2=new Runnable1_ex('a');
   Thread th1=new Thread(ru1);
       Thread th2=new Thread(ru2);
   th1.start();
   th2.start();
   System.out.println("activecount"+Thread.activeCount());
 }
}
为什么说找不到符号方法getName();Thread线程不是已经赋名为th1,th2了吗,
应该怎么样解决

解决方案 »

  1.   

    楼主先学会怎么贴代码吧。要像这样:int a = 0;
    if (a > 0) {
        System.out.println("Haha!");
    }
      

  2.   

    看一下Thread的源码 就清楚了!start()调用的是Runnable1_ex中的run()方法 ,你在在Runnable1_ex中没有定义getName()方法
      

  3.   

    Runnable1_ex implements Runnable
    你是实现的Runnable借口,又没定义getName方法 肯定有问题啊..你可以加个方法就好了..
    private char getName() {
    return this.c;
    }
      

  4.   


      System.out.print(getName()+":");//等价于System.out.print(this.getName()+":");
                                      //this指的是当前所在的类的对象,即Runnable1_ex类的对象,而Runnable1_ex类并没有getName()方法,  //可修改为:
      System.out.print(Thread.currentThread().getName()+":");//
      

  5.   

    wo也找不到符号方法getName(),哈哈..
      

  6.   

    看Thread类的源代码 和 Runnable接口的源代码吧    Thread类其实也是实现了Runnable接口的一个类而已,而getName()方法是Thread类自己定义的,你定义的Runnable接口现实类并没有定义getName方法。你使用start方法调用的是你自定义的那个Runnable接口实现类的run方法而非Thread类的run方法,所以你会抛出那个异常
      

  7.   

    正解,你都没有定义,怎么会有
    --signature--------------------------
    http://www.lunwenwa.com/qikanlunwen/