我非常接近最后使用命令行为JCDK 2.2.2创建CAP文件。我首先将源文件Transfer.java编译成一个类文件Transfer.class,然后尝试生成CAP文件。一切都很好,只是我试图建立从类文件我的Java小程序卡时,从CAP转换工具得到错误CAP转换器失败,出现'不受支持的int类型的中间值,必须将值转换为short或byte类型'
error: line 56: smartTransfer.Transfer: unsupported int type of intermediate value, must cast intermediate value to type short or byte.
。我不知道这个错误来自哪里,因此无法将该值分配给一个字节或一个字节。
我记得当我用JCDK 3.0.5安装了Eclipse Neon时,出现了一个未知位置的int错误,但小程序仍然运行。我想由于我的系统上的JRE。
这里是我的applet代码:
package smartTransfer;
import javacard.framework.*;
public class Transfer extends Applet {
final static byte CLASS = (byte) 0x80;
final static byte WRITE_USER_INFO_INS = 0x07;
final static byte WRITEIT_USER_INFO_INS = 0x08;
final static byte READ_USER_INFO_INS = 0x09;
final static byte READIT_USER_INFO_INS = 0x06;
final static byte SIZE_MEMORY = (short) 127;
static byte[] memory;
static byte[] memoryy;
public static void install(byte[] bArray, short bOffset, byte bLength) throws ISOException {
new Transfer().register();
memory = new byte[SIZE_MEMORY];
memoryy = new byte[SIZE_MEMORY];
}
public void process(APDU apdu)
throws ISOException {
if (selectingApplet()) return;
byte[] buffer = apdu.getBuffer();
if (buffer[ISO7816.OFFSET_CLA] !=CLASS) {
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
}
byte ins = buffer[ISO7816.OFFSET_INS];
switch (ins) {
case READ_USER_INFO_INS:
readUserInfo(apdu);
break;
case READIT_USER_INFO_INS:
readitUserInfo(apdu);
break;
case WRITE_USER_INFO_INS:
writeUserInfo(apdu);
break;
case WRITEIT_USER_INFO_INS:
writeitUserInfo(apdu);
default:
ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
}
}
private void writeUserInfo(APDU apdu) {
byte[] cmd_apdu = apdu.getBuffer();
if (cmd_apdu[ISO7816.OFFSET_P1] != 0x00)
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short offset = (short) (cmd_apdu[ISO7816.OFFSET_P2] & 0x00FF);
if (offset >= SIZE_MEMORY)
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short lc = (short)(cmd_apdu[ISO7816.OFFSET_LC] & 0x00FF);
if ((offset + lc) > SIZE_MEMORY)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
if (lc == 0x00)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
getAPDUBody(apdu);
Util.arrayCopy(cmd_apdu, (short)((ISO7816.OFFSET_CDATA) & 0x00FF),
memory, offset, lc);
ISOException.throwIt(ISO7816.SW_NO_ERROR);
}
public void getAPDUBody(APDU apdu) {
byte[] buffer = apdu.getBuffer();
short lc = (short)(buffer[ISO7816.OFFSET_LC] & 0x00FF);
if (lc != apdu.setIncomingAndReceive())
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
}
private void readUserInfo(APDU apdu) {
byte[] cmd_apdu = apdu.getBuffer();
if (cmd_apdu[ISO7816.OFFSET_P1] != 0x00) ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short offset = (short) (cmd_apdu[ISO7816.OFFSET_P2] & 0x00FF);
if (offset >= SIZE_MEMORY) ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short le = (short)(cmd_apdu[ISO7816.OFFSET_LC] & 0x00FF);
if (le == 0x00) le = (short)(SIZE_MEMORY - offset);
if ((offset + le) > SIZE_MEMORY) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
apdu.setOutgoing();
apdu.setOutgoingLength((short)le);
apdu.sendBytesLong(memory, (short)offset, (short)le);
}
private void writeitUserInfo(APDU apdu) {
byte[] cmd_apdu = apdu.getBuffer();
if (cmd_apdu[ISO7816.OFFSET_P1] != 0)
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short offset = (short) (cmd_apdu[ISO7816.OFFSET_P2] & 0x00FF);
if (offset >= SIZE_MEMORY)
ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short lc = (short)(cmd_apdu[ISO7816.OFFSET_LC] & 0x00FF);
if ((offset + lc) > SIZE_MEMORY)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
if (lc == 0x00)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
getAPDUBody(apdu);
Util.arrayCopy(cmd_apdu, (short)((ISO7816.OFFSET_CDATA) & 0x00FF),
memoryy, offset, lc);
ISOException.throwIt(ISO7816.SW_NO_ERROR);
}
private void readitUserInfo(APDU apdu) {
byte[] cmd_apdu = apdu.getBuffer();
if (cmd_apdu[ISO7816.OFFSET_P1] != 0x00) ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short offset = (short) (cmd_apdu[ISO7816.OFFSET_P2] & 0x00FF);
if (offset >= SIZE_MEMORY) ISOException.throwIt(ISO7816.SW_WRONG_P1P2);
short le = (short)(cmd_apdu[ISO7816.OFFSET_LC] & 0x00FF);
if (le == 0x00) le = (short)(SIZE_MEMORY - offset);
if ((offset + le) > SIZE_MEMORY) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
apdu.setOutgoing();
apdu.setOutgoingLength((short)le);
apdu.sendBytesLong(memoryy, (short)offset, (short)le);
}
}
我知道错误是在第56行,但我想这将是从Transfer.class文件(我无法打开阅读),而不是在源代码中。但是当我读取传入的APDU头时,我能想到的唯一未分配的中间值就是指令案例。
这个错误从哪里来?
*“我知道错误在第56行。“*我希望我们知道哪一行是第56行。缺少进口和包装声明,我不会尝试猜测。为了尽快提供更好的帮助,请发布[MCVE]或[简短,独立,正确的示例](http://www.sscce.org/)。 MCVE/SSCCE要求包含重新创建问题所需的所有代码。 –
嗨安德鲁,对不起,我没有意识到,我没有在他们身后做两行四行,他们结束了上面的文字 - 我改变了它....正如我所说,我会认为第56行是指到.class文件,我转换为上限文件,这我无法打开阅读,这就是为什么我没有上传 - 你想我附上它 - 这是我第一次这样做,所以请裸露在我身边。 –
*“我以为第56行是指.class文件”*否,它指的是生成类文件的Java源代码文件!请参阅[什么是堆栈跟踪,以及如何使用它来调试我的应用程序错误?](http://stackoverflow.com/q/3988788/418556) –