-1

I have a problem with "possible lossy conversion from int to byte" error, but I am not converting integer to byte in my code.

    public static void main(String[] args) {
  Notebook ntb = new Notebook("Acer","Aspire",15000.0f,20,"Intel Core I73632QM",4,2.2f,"GeForce GT720M",2,8,1000,15.6f,100,150,"DVD");  //<- error here
}

And here is Notebook class

package semestralka;


public class Notebook extends produkt.Produkt{
    private String procesor;
    private byte pocetJader;
    private float frekvence;
    private String GPU;
    private byte pametGPU;
    private byte operacniPamet;
    private int pevnyDisk;
    private float uhloprickaDispleje;
    private int sirka;
    private int vyska;
    private String mechanika;

    public Notebook(String vyrobce, String model, float cena, int pocet, String procesor, byte pocetJader, float frekvence, String GPU, byte pametGPU, byte operacniPamet, int pevnyDisk, float uhloprickaDispleje, int sirka, int vyska, String mechanika) {
        this.vyrobce = vyrobce;
        this.model = model;
        this.cena = cena;
        this.pocet = pocet;
        this.procesor = procesor;
        this.pocetJader = pocetJader;
        this.frekvence = frekvence;
        this.GPU = GPU;
        this.pametGPU = pametGPU;
        this.operacniPamet = operacniPamet;
        this.pevnyDisk = pevnyDisk;
        this.uhloprickaDispleje = uhloprickaDispleje;
        this.sirka = sirka;
        this.vyska = vyska;
        this.mechanika = mechanika;
    }


    //getters
    public String getProcesor() {
        return procesor;
    }

    public byte getPocetJader() {
        return pocetJader;
    }

    public String getGPU() {
        return GPU;
    }

    public byte getPametGPU() {
        return pametGPU;
    }

    public byte getOperacniPamet() {
        return operacniPamet;
    }

    public int getPevnyDisk() {
        return pevnyDisk;
    }

    public float getUhloprickaDispleje() {
        return uhloprickaDispleje;
    }

    public int getSirka() {
        return sirka;
    }

    public int getVyska() {
        return vyska;
    }

    public String getMechanika() {
        return mechanika;
    }







}

I don't know why I am getting this error. Can anyone help me please? Thank you.

Matěj Řehák
  • 79
  • 3
  • 10

1 Answers1

3

You place the 4 in the constructor which is an int, but your constructor wants a byte so that is why an int is going to be converted to a byte and that is why you get the error/warning. Why you want to use a byte? You can just use an int and the problem is solved, isn't it?

martijnn2008
  • 3,552
  • 5
  • 30
  • 40
  • Thank you very much for advice. I am using byte because I know that some parameters will not exceed value 255, so it is unnecessary to use integer. – Matěj Řehák May 01 '14 at 12:10
  • 3
    @MatějŘehák you said "I am not converting integer to byte in my code", but you *are* - when you call the constructor you pass the `int` value `20`, while the constructor expects a `byte`. You can cast it to `byte`: `new Notebook("Acer","Aspire",15000.0f,(byte) 20,...` – Jesper May 01 '14 at 12:13