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;

    protected void onCreate(Bundle savedInstanceState) {

        // Assign the Views from the layout file to the corresponding variables
        factTextView = findViewById(;

1 Answer

Seth Kroger
Seth Kroger
56,351 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
56,351 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 =)