When I run the following lines of code the following erroe from the compiler is displayed

cannot find symbol - method start()

CODE:

import java.lang.Thread;
import java.util.concurrent.*;

public class MyThread
{
    public static final int MAX = 15;
    private String message;
    
    /**
     * Constructor with parameters 
     * 
     * @param message string to be used
     */
    public MyThread(String m)
    {
        message = m;
    }
    
    /**
     * run method always void nothing to be
     * returned.
     */
    public void run()
    {
        for(int i = 0; i <= MAX; i++)
        {
            System.out.println(message);
        }
    }
}
import java.lang.Thread;
import java.util.concurrent.*;
import java.util.*;

public class TestMyThread
{
    public static void main (String[] args)
    {
        MyThread t1 = new MyThread("hello");
        MyThread t2 = new MyThread("goodbye");
        
        t1.start();
        t1.join();
        t2.start();
    }        
}

Edited 4 Years Ago by kyriacos1986: n/a

wheres your

public class TestMyThread extends Thread {}

and the same applies for your MyThread class it should have a

public class MyThread extends TestMyThread {}

, also try putting that in first
and also try starting your thread using this:

TestMyThread tmt = new TestMyThread();
        MyThread mt=tmt.new MyThread("Hello");
        mt.start();
        mt.join();

this is how you might fix it with the least changes

Edited 4 Years Ago by DavidKroukamp: n/a

maybe not necessarily to solve your problem, but if you want to define your own threads, it's better to implement Runnable, than to extend thread.

the only reason why you should extend is if you want to change something in the basic functionality of the object, which is most likely not what you're doing.

extending just makes it impossible to extend any other class if you ever would want to do so, but there is no limit as to how many interfaces you can implement.

This is an easier way, than the multi-threading. It allows you to set the time, instead of the counter variable within the thread need to constantly manually. In addition, any set time will run on systems running the same thread will run as fast as possible to allow the current processor.

Comments
unk???
what are you talking about? and the thread is SOLVED
This question has already been answered. Start a new discussion instead.