Ebrahim Ghasemi
Ebrahim Ghasemi

Reputation: 6136

Weird "illegal start of expression" error in Netbeans

In the following programs, command is a byte array field in Apdu class. The problem is that my IDE (Netbeans) mark the line of

apdu.command = {(byte) 0x00, (byte)0xa4, (byte) 0x00, (byte) 0x00};

As error, with the message illegal start of expression, while it is okay to use the following instead:

byte[] bytes = {(byte) 0x00, (byte) 0xa4, (byte) 0x00, (byte) 0x00};
apdu.command = bytes;

What's wrong with the first programs?


First program: enter image description here

Second Program: enter image description here

Upvotes: 0

Views: 1069

Answers (2)

Ramanlfc
Ramanlfc

Reputation: 8354

array syntax {} can only be used for initialization not for assignment.

you need to use apdu.command =new byte[] {(byte) 0x00, (byte)0xa4, (byte) 0x00, (byte) 0x00};.

Upvotes: 1

Eran
Eran

Reputation: 394136

You need to initialize the array variable with :

apdu.command = new byte[] {(byte) 0x00, (byte)0xa4, (byte) 0x00, (byte) 0x00};

The initialization you tried is only valid in array declaration expressions.

Upvotes: 1

Related Questions