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 trialLinus Karlsson
7,402 PointsCannot cast with alt+enter
I cannot seem to cast with the alt+enter combination. I have declared the variable and written everything as perfect as I can.
Can someone have a look at what I'm doing wrong, please?
public class FunFactsActivity extends AppCompatActivity {
// Declare our view variables
private TextView factTextView;
private Button showFactButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fun_facts);
// Assign the Views from the layout file to the corresponding variables
factTextView = findViewById(R.id.factTextView);
1 Answer
Seth Kroger
56,414 PointsRecently changes to the API and Android Studio get rid of the need for an explicit cast so there isn't a problem detected that can be corrected with quick-fix. (Old habits do die hard, though. You can always manually type in the cast.)
Linus Karlsson
7,402 PointsLinus Karlsson
7,402 PointsThat is actually what I did and it worked the same! I typed it manually like it would look like after I would have cast it.
Is just that the alt+enter combination is quicker and matching what the teacher is doing.
Seth, would you worry about an issue like this or just keeping going the way I am doing already? That is manually typing casts whenever I have to in Android Studio?
Seth Kroger
56,414 PointsSeth Kroger
56,414 PointsYou can continue manually typing and not worry about it. If leaving the cast off doesn't cause any "red squiggily" errors you can do that too.
Linus Karlsson
7,402 PointsLinus Karlsson
7,402 PointsThank you, Seth! I think I will do that then =)