I am following a starting tutorial for Threading in Java.
The code is very basic
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());
}
}
But I get a parsing error in this line
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)
I am using the same code here http://www.javabeginner.com/learn-java/java-threads-tutorial
I searched for this error but couldn’t find anything.
Thanks in advance
Delete your own definition of Runnable interface