D P. D P. - 2 months ago 6
Java Question

Inserting data in to a 2 dimensional byte[] array

I am new to Java and trying to use a two dimensional byte[ ] type. I have created a 2D

byte[]
array as shown bellow. But whenever I try to insert some data to it, it gives an error saying:
NullPointerException


byte[][][] Requisition = new byte[10][][];
byte[] someinput = ("example").getBytes();
Requisition[0][0]=someinput;
System.out.println("Printing:" + Requisition[0][0].toString());
etc..


Data type I am inserting in to this 2D array is type
byte[]
. Because what I am inserting is an encrypted data, these data will have the format of byte[ ] , not byte

I want
Requisition
array to hold two inputs for one line. For example

Requisition[0][1]=someinput1;
Requisition[0][2]=someinput2;


This
someinput1
I am wanting to insert is not type
byte
. Data I am inserting will be
byte[]
type.

What I mean byte[] is (sequence of bytes using the platform's default charset, storing the result into a new byte array.)

Answer

It should be:

byte[][][] someinput = new byte[5][5][5];

Then you can insert data in to this array.

Comments