Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java卡小程序中使用可共享接口?_Java_Javacard - Fatal编程技术网

如何在Java卡小程序中使用可共享接口?

如何在Java卡小程序中使用可共享接口?,java,javacard,Java,Javacard,我为我的java卡编写了两个名为App1和App2的简单小程序,如下所示: App1: public class App1 extends Applet { private App1() { } public static void install(byte bArray[], short bOffset, byte bLength) throws ISOException { new App1().register();

我为我的java卡编写了两个名为App1和App2的简单小程序,如下所示:

App1:

public class App1 extends Applet {

    private App1() {
    }

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

    public void process(APDU arg0) throws ISOException {
    if(selectingApplet()){
        return;
    }
     //I want to call "ThisMethod()" of App2 here


    }

}
public class App2 extends Applet {

    private App2() {
    }

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

    public void process(APDU arg0) throws ISOException {

    }

    public void ThisMethod(){
        ISOException.throwIt((short)0x9001);
    }

}
App2:

public class App1 extends Applet {

    private App1() {
    }

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

    public void process(APDU arg0) throws ISOException {
    if(selectingApplet()){
        return;
    }
     //I want to call "ThisMethod()" of App2 here


    }

}
public class App2 extends Applet {

    private App2() {
    }

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

    public void process(APDU arg0) throws ISOException {

    }

    public void ThisMethod(){
        ISOException.throwIt((short)0x9001);
    }

}
正如我在App1程序(作为注释)中指出的,我想在App1的
过程
方法中调用App2的
ThisMethod
方法。据我所知,我必须实现
可共享
接口。但我对此有点困惑:

问题:

public class App1 extends Applet {

    private App1() {
    }

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

    public void process(APDU arg0) throws ISOException {
    if(selectingApplet()){
        return;
    }
     //I want to call "ThisMethod()" of App2 here


    }

}
public class App2 extends Applet {

    private App2() {
    }

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

    public void process(APDU arg0) throws ISOException {

    }

    public void ThisMethod(){
        ISOException.throwIt((short)0x9001);
    }

}
1-我应该在两个小程序中都实现此方法吗?或者我需要在App1或App2中实现它

2-如果App1和App2在一个包或两个单独的包中,它会改变什么吗

3-我是否需要
Shareable
接口来共享阵列?还是仅仅为了共享方法而强制

  • 不,您只需要创建一个扩展Shareable的接口,然后您的app2就必须实现该接口

  • 没关系

  • 是的,如果要共享阵列,您还需要实现
    Shareable

  • 但是,在使用从其他小程序实例共享的方法/对象之前,必须先将接口实例存储在App1中。你可以这样做

    AID aid = JCSystem.lookupAid({App2 AID byte array}, {offset}, {length});  // provide the instance AID of App2
    
    {yourInterface} app2Instance = ({yourInterface})JCSystem.getAppletShareableInterfaceObject(aid, (byte)0);
    

    然后使用
    app2Instance
    访问共享的方法/对象

    我遵循上述步骤,但出现了一个新问题,如果您看一下,我将不胜感激:对不起,我以一种对我有效的方式更改了答案。若你们发现有什么不对劲,请告诉我。答案部分是错的。参考后续帖子:@PaulBastian我编辑了这个答案,如果你认为它是正确的,也许你想删除你的评论。(稍后我将删除此评论。)