-1

I am learning Java Programming and I am a beginner. I am in Multithreading Concept now. When I execute the below program, I getting errors like

Errors

X cannot be resolved to a type
X cannot be resolved to a type

ThreadX cannot be resolved

at ThreadTest.main(ThreadTest.java:20)

Code

public Class X implements Runnable
{
        public void run()
        {
            for(int i=0;i<=10;i++)
            {
                System.out.println("\tValue of ThreaadX : "+i);
            }
            System.out.println("End of ThreadX");
        }
}

public class ThreadTest {
    public static void main(String[] args) {

        X runnable = new X();
        Thread Threadx = new Thread(runnable);
        ThreadX.start();
        System.out.println("END OF THREADX");
    }

}

What mistake I did in the Main Method. I getting this error When I tried to create an object 'runnable' of the class X.

Thanks in advance

Qadir Hussain
  • 1,263
  • 1
  • 10
  • 26
sparkey
  • 154
  • 3
  • 13
  • 4
    `class X` (with a lowercase c). Also you're declaring a variable named `Threadx` and then you're doing `ThreadX.start()`. Java is case-sensitive. – Alexis C. Jan 18 '14 at 10:34
  • The program runs perfectly with ZouZou's modifications. Why did you not write that in a comment instead of as an answer ? – Vulpo Jan 18 '14 at 10:41
  • This may be helpful : http://stackoverflow.com/questions/1333377/how-to-update-swt-gui-from-another-thread-in-java – Seyed Hamed Shams Jan 18 '14 at 10:43
  • You might consider using an IDE (e.g. Eclipse, NetBeans). This would highlight this basic syntax errors. – Tobias Kremer Jan 18 '14 at 11:21

3 Answers3

3

Java syntax is case sensitive

Thread Threadx = new Thread(runnable);
ThreadX.start(); //it should be 'x' lowercase at the end of the ThreadX variable

You need to change it to

  Thread Threadx = new Thread(runnable);
  Threadx.start(); 
Keerthivasan
  • 12,760
  • 2
  • 32
  • 53
  • I am getting a new exceptins nw like below **Exception in thread "main" java.lang.Error: Unresolved compilation problem: The public type X must be defined in its own file at X.(ThreadTest.java:1) at ThreadTest.main(ThreadTest.java:18)** – sparkey Jan 18 '14 at 10:43
  • 1
    That's a different question. but, i will help you. Public Class should have their own file. i.e. you should have X.java for public class X and ThreadTest.java for ThreadTest class – Keerthivasan Jan 18 '14 at 10:45
0

Replace this line ThreadX.start(); with Threadx.start();. Because in java object's name is case sensitive so ThreadX is not equivalent to Threadx. That's why you were getting error.

Qadir Hussain
  • 1,263
  • 1
  • 10
  • 26
0

use this. Check the name of thread Threadx 'x' small.

Thread Threadx = new Thread(runnable);
            Threadx.start();//it is 'X'(capital in your case)

Check out naming conventions

Saurabh Sharma
  • 489
  • 5
  • 20