Java线程中的语法错误

Mar*_*iam 1 java multithreading

我正在学习Java中的线程入门教程.代码非常基础

public interface Runnable {

void run();

}

public class RunnableThread implements Runnable {

    Thread runner;
    public RunnableThread() {
    }
    public RunnableThread(String threadName) {
        runner = new Thread(this, threadName); // (1) Create a new thread.
        System.out.println(runner.getName());
        runner.start(); // (2) Start the thread.
    }
    public void run() {
        //Display info about this particular thread
        System.out.println(Thread.currentThread());
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我在这个行中获得了一个解析错误:runner = new Thread(this,threadName);

   no suitable constructor found for Thread(RunnableThread,java.lang.String)
constructor java.lang.Thread.Thread(java.lang.ThreadGroup,java.lang.Runnable,java.lang.String,long) is not applicable
  (actual and formal argument lists differ in length)
constructor java.lang.Thread.Thread(java.lang.ThreadGroup,java.lang.Runnable,java.lang.String) is not applicable
  (actual and formal argument lists differ in length)
constructor java.lang.Thread.Thread(java.lang.Runnable,java.lang.String) is not applicable
  (actual argument RunnableThread cannot be converted to java.lang.Runnable by method invocation conversion)
constructor java.lang.Thread.Thread(java.lang.ThreadGroup,java.lang.String) is not applicable
  (actual argument RunnableThread cannot be converted to java.lang.ThreadGroup by method invocation conversion)
constructor java.lang.Thread.Thread(java.lang.String) is not applicable
  (actual and formal argument lists differ in length)
constructor java.lang.Thread.Thread(java.lang.ThreadGroup,java.lang.Runnable) is not applicable
  (actual argument RunnableThread cannot be converted to java.lang.ThreadGroup by method invocation conversion)
constructor java.lang.Thread.Thread(java.lang.Runnable) is not applicable
  (actual and formal argument lists differ in length)
constructor java.lang.Thread.Thread() is not applicable
  (actual and formal argument lists differ in length)
Run Code Online (Sandbox Code Playgroud)

我在这里使用相同的代码http://www.javabeginner.com/learn-java/java-threads-tutorial

我搜索了这个错误但找不到任何东西.

提前致谢

Pet*_*rey 7

您已经创建了自己的Runnable接口.我建议你删除它以避免混淆.