error: incompatible types: inferred type does not conform to upper bound(s) inferred: INT#1 upper bound(s):

error: incompatible types: inferred type does not conform to upper bound(s) inferred: INT#1 upper bound(s):

我真的不知道如何解决这个问题(错误:类型不兼容:推断类型不符合上限推断:INT#1 上限:Giocatore[],Parcelable where INT#1 是交集类型:INT#1 extends Giocatore[],Parcelable).

它在“Giocatore[] gio = intent.getParcelableExtra("giocatori");”行显示错误。

public class Giocatore implements Parcelable {

    private String nome;
    private String ruolo;
    private double valore;

    public Giocatore(String nome, String ruolo, double valore) {
        setNome(nome);
        setRuolo(ruolo);
        setValore(valore);
    }
    //getters and setters
    protected Giocatore(Parcel in) {
        nome = in.readString();
        ruolo = in.readString();
        valore = in.readDouble();
    }

    public static final Creator<Giocatore> CREATOR = new Creator<Giocatore>() {
        @Override
        public Giocatore createFromParcel(Parcel in) {
            return new Giocatore(in);
        }

        @Override
        public Giocatore[] newArray(int size) {
            return new Giocatore[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(nome);
        dest.writeString(ruolo);
        dest.writeDouble(valore);
    }
}

Class "Squadra"

public class Squadra {

    private int componenti;
    private String coloreMaglia;
    private Giocatore[] squadra;

    public Squadra() {
        this.componenti = 5;
        this.coloreMaglia = null;
        squadra = new Giocatore[5];
    }

    public Giocatore[] getSquadra() {
        return this.squadra;
    }
}

Class "SecondaPagina"

public class SecondaPagina extends AppCompatActivity  implements AdapterView.OnItemSelectedListener {

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

        final Giocatore[] giocatori = new Giocatore[10];

        Button next = findViewById(R.id.crea);
        Button procedi = findViewById(R.id.procedi);
        procedi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
               //some code
               int pos = aggiungi(giocatori, new Giocatore(n, r, v)); //function "aggiungi" add an object "Giocatore" to the array "giocatori" and return the position where the object has been added (100% works)
               //some code
             }
        });
        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent(SecondaPagina.this, TerzaPagina.class);
                intent.putExtra("giocatori", giocatori);
                startActivity(intent);
            }
        });
    }
}

public class TerzaPagina extends AppCompatActivity {

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

        Intent intent = getIntent();
        Giocatore[] gio = intent.getParcelableExtra("giocatori");
    }
}

错误:类型不兼容:推断类型不符合上限 推断:INT#1 上界:Giocatore[],Parcelable 其中 INT#1 是交集类型: INT#1 扩展了 Giocatore[],Parcelable

它在“Giocatore[] gio = intent.getParcelableExtra("giocatori");”行显示错误。

请帮助我,谢谢。

尝试使用:

(Giocatore[]) intent.getParcelableArrayExtra("giocatori");

而不是

intent.getParcelableExtra(...);