cant use runnable

Discussion in 'Java' started by cryfreak, Jan 9, 2010.

  1. cryfreak

    cryfreak New Member

    Joined:
    Jan 9, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    when implementing runnable i cant pass a runnable to a Thread.
    Code:
     
    class A implements Runnable{
        public void run(){
            System.out.println("run");
        }
    public static void main(String[]args){
        A a=new A();
        Thread t=new Thread(a); // this is where the error occurs
        t.start();
    }
    }
    
    my friends say that it woks fine.i went through a couple of articles on the internet according to them theres no way that code doesnt work.i tried reinstalling jdk that didnt work either.is something wrong with my complier? or is there something i missed? pls help
     
  2. cryfreak

    cryfreak New Member

    Joined:
    Jan 9, 2010
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    the error end up getting is "cannot find symbol constructor Thread(A)".when i extend Thread it works fine.and if i leave the thread constructor empty(not passing a runnable)it compiles.
     
  3. ewaldhorn

    ewaldhorn New Member

    Joined:
    Feb 16, 2010
    Messages:
    36
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Developer
    Location:
    Cape Town, South Africa
    Home Page:
    http://www.javak.co.za
    Hi.

    I put it all in a java file called A.java and it works as expected?

    What IDE / Development environment are you using?

    Best regards
    Ewald
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice