简体   繁体   中英

Android Studio Check Box

I'm looking for help with this error:

error: incompatible types: no unique maximal instance exists for type variable T with upper bounds CheckBox,View where T is a type-variable: T extends View declared in method findViewById(int)

...which I get when running this code:

public class CheckBox extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_check_box);

        CheckBox checkbox1 = new CheckBox();
        checkbox1 = findViewById(R.id.bx1);
    }
}

You need to cast the checkbox because the returned form findViewById is generic

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_check_box);

    CheckBox checkbox1 = (Checkbox) findViewById(R.id.bx1);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM