This discussion is archived
2 Replies Latest reply: Jan 17, 2013 11:02 AM by safarmer RSS

ERROR :Unsupported bytecode anewarray in clinit method.

965207 Newbie
Currently Being Moderated
I have the following java card applet, and in the same package I have another java class called Users. When I try to convert the applet into CAP file I got the error message Unsupported bytecode anewarray in clinit method
The applet is here

package classes;

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.JCSystem;

public class MainApplet extends Applet {
     
     private static final byte MAIN_APPLET_CLA = (byte) 0xA0;
     private static final byte MAIN_APPLET_INS_ADD = (byte) 0x10;
     private static final byte MAIN_APPLET_INS_GET = (byte) 0x20;
     
     private static final short MAX_SIZE = (short) 0xFF;
     private static Users[] sysUsers = new Users[(short) 200];
     
     private static final short CLA_ERROR = (short) 0x13;
     private static final short INS_ERROR = (short) 0x14;
     private static final short NO_DATA_FOUND = (short) 0x15;
     private static final short NO_SUCH_INDEX = (short) 0x16;

     
     private static short index = 00;

     private MainApplet() {
     }

     public static void install(byte bArray[], short bOffset, byte bLength)
    {
          new MainApplet().register();
     }

     public void process(APDU apdu) {
          // TODO Auto-generated method stub
          if(selectingApplet())
               return;
          byte[] buffer = apdu.getBuffer();
          if(buffer[ISO7816.OFFSET_CLA] != MAIN_APPLET_CLA )
               ISOException.throwIt(CLA_ERROR);
          switch(buffer[ISO7816.OFFSET_INS] & (byte) 0xFF)
          {
          case MAIN_APPLET_INS_ADD :
               addUser(apdu);
               break;
          case MAIN_APPLET_INS_GET :
               getUser(apdu);
               break;
          default : ISOException.throwIt(INS_ERROR);
               
          }
     }
     
     public void addUser(APDU apdu)
     {
          byte[] buffer = apdu.getBuffer();
          short p1 = (short) buffer[ISO7816.OFFSET_P1];
          short p2 = (short) buffer[ISO7816.OFFSET_P2];
          
          JCSystem.beginTransaction();
          
          byte[] user = new byte[p1];
          byte[] pass = new byte[p2];
          for(short i = 0; i < p1; i++)
               user[i] = buffer[(short) (5 + i)];
          for(short j = 0; j < p2; j++)
               pass[j] = buffer[(short)(5 + p1 + j)];
          Users  u1 = new Users(user , pass);
          sysUsers[index] = u1;
          index ++;
          
          JCSystem.commitTransaction();
          return;
          
     }
     
     public void getUser(APDU apdu)
     {
          byte[] buffer = apdu.getBuffer();
          short p1 = (short)(buffer[ISO7816.OFFSET_P1]);
          if(p1 >= index)
               ISOException.throwIt(NO_SUCH_INDEX);
          Users u = sysUsers[p1];
          byte[] name = u.getNames();
          byte[] pass = u.getPasss();
          short id = u.getID();
          
          for(short i = 0; i < (short) name.length; i++)
               buffer[i] = name;
          short counter = (short) name.length;
          for(short j = 0; j < (short) pass.length; j++)
               buffer[(short)(counter + j)] = pass[j];
          short len = (short) (name.length + pass.length);
          buffer[len] = (byte) id;
          apdu.setOutgoingAndSend((short) 0,(short)(len +1 ));
          
     }

}
and the USers class code is here 
package classes;

public class Users {

     private byte[] names;
     private byte[] passs;
     private short nIndex;
     private short pIndex;
     private short ID;
     
     private static final short namesLength = (short) 0x09;
     private static final short passLength = (short) 0x09;
     private static short counter = 00;
     
     private short namesIndex = 00;
     private short passIndex = 00;
     
     Users(byte[] n, byte[] p)
     {
          names = new byte[namesLength];
          passs = new byte[passLength];
          
          for(short i = 0; i < (short) names.length; i++)
          {
               names[i] = n[i];
               namesIndex++;
          }
          nIndex = namesIndex;
          
          for(short j = 0; j < (short) names.length; j++)
          {
               passs[j] = p[j];
               passIndex++;
          }
          pIndex = passIndex;
          
          ID = counter;
          counter++;
     }

     public byte[] getNames() {
          return names;
     }

     public void setNames(byte[] names) {
          this.names = names;
     }

     public byte[] getPasss() {
          return passs;
     }

     public void setPasss(byte[] passs) {
          this.passs = passs;
     }

     public short getnIndex() {
          return nIndex;
     }

     public void setnIndex(short nIndex) {
          this.nIndex = nIndex;
     }

     public short getpIndex() {
          return pIndex;
     }

     public void setpIndex(short pIndex) {
          this.pIndex = pIndex;
     }

     public short getID() {
          return ID;
     }

     public void setID(short iD) {
          ID = iD;
     }
     
     
     
}
I don't know how to solve this error !! Any help ??                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points