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

Attila Vago
PLUS
Attila Vago
Courses Plus Student 15,286 Points

In case TextView and Button turn red in Android Studio

This just happened to me for some reason, but I found a fix, so I am sharing it. Your import from the top of the FunFactsActivity.java file might be missing these 2 lines of code, thus being unable to compile.

import android.widget.Button;
import android.widget.TextView;

After adding these 2 lines, everything compiles just fine.

4 Answers

Stone Preston
Stone Preston
42,016 Points

this happens when you dont use autocomplete. If you use autocomplete, android studio automatically imports the classes for you. if you dont use autocomplete, you will have to import them yourself

Attila Vago
PLUS
Attila Vago
Courses Plus Student 15,286 Points

Apparently that's not necessarily true since in my case auto-complete was in fact on. I think it's a beta caused issue, which is why I posted the tip.

Stone Preston
Stone Preston
42,016 Points

I meant that you have to select/press enter to select the auto completed value when typing Button, text view etc to get the class to auto import, not have autocomplete on or off. If you type out Button yourself without using the autocompleted value then it wont import them. I think this is the normal behavior of android studio

Attila Vago
PLUS
Attila Vago
Courses Plus Student 15,286 Points

I see. Well, yes, in that case you were right. That is indeed the reason. Brilliant. Now we all know why that could happen. :)

any update on this because nothing is working