Android Build a Simple Android App with Java Basic Android Programming Making a Button Do Something

Cannot 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
MOD
Seth Kroger
Treehouse Moderator 56,267 Points

Recently 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.)

That 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
Seth Kroger
Treehouse Moderator 56,267 Points

You 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.

Thank you, Seth! I think I will do that then =)