Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to assign getBytes() to byte array

I'm completely stumped.. Seems like there'd be a simple solution

private Byte[] arrayOfBytes = null;    

public Data(String input) {
    arrayOfBytes = new Byte[input.getBytes().length];
    arrayOfBytes = input.getBytes();
}

Throws the follwing error:

incompatible types
    required: java.lang.Byte[]
    found: byte[]
like image 333
Marshma11ow Avatar asked Mar 30 '26 22:03

Marshma11ow


1 Answers

getBytes() from String returns a byte[] and you are trying to affect it to a Byte[].

byte is a primitive whereas Byte is a wrapper class (kind of like Integer and int).

What you can do is change :

private Byte[] arrayOfBytes = null;

to :

private byte[] arrayOfBytes = null;
like image 125
talnicolas Avatar answered Apr 01 '26 11:04

talnicolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!