Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Threads and Services Threads in Android Extending Thread

Jahdiel Alvarez
Jahdiel Alvarez
10,566 Points

New inner class is not seen by compiler.

The compiler doesn't seem to see the inner class created, which extends Thread.

MainActivity.java
public class MainActivity extends Activity {
    final TwitterClient twitterClient = new TwitterClient();

    @Override
    public void onCreate(Bundle savedInstanceState) {
      setContentView(R.layout.activity_main);

      Awesome t = new Awesome(twitterClient);
      t.setName("TwitterThread");
      t.start();
    }

    private class Awesome extends Thread {

        private TwitterClient mTwit;
        public Awesome(TwitterClient t) {
          mTwit = t;
        }

        @Override
        public void run(){
            mTwit.update();    
        }
  }


}

2 Answers

Jason Wiram
Jason Wiram
42,762 Points

The challenge verification must use a default constructor for your new inner class (not that you would or should know this). Since you created a custom constructor, when the verification is running it is not passing because your inner class constructor doesn't match what it is expecting. If you add a default constructor to your class it will pass. As a tip, when doing these challenges, if you add a custom constructor, I would always add a default as well. It's hard to predict what the test validation is using. Just add this to your inner class:

public Awesome() {}
Jahdiel Alvarez
Jahdiel Alvarez
10,566 Points

Thanks, I already solved it the problem as you said was in adding the constructor and making the class private.