InvocationTargetException:使用Aion嵌入式AVM时Dapp调用失败

时间:2019-03-21 21:15:44

标签: java blockchain aion

使用maven和嵌入式AVM调用合同时,我收到以下消息:

[ERROR] Failed to execute goal org.aion4j:aion4j-maven-plugin:0.5.0-beta1:call (default-cli) on project supercontract: Method call failed: InvocationTargetException: Dapp call failed. Code: FAILED, Reason: null -> [Help 1]

我刚刚编辑了HelloAvM项目时获得的mvn initialize合同。这是整个合同:

public class HelloAvm {
    // Voting App
    // 1. Users call a function to find out what the question is.
    // 2. They then call another function with their choice.
    // 3. Any use can call the results() function to find out what the current votes are.

    public static int questionNumber = 1;
    public static String questionString = "Is Haggis a real animal?";

    public String getQuestion() {
        return "Question #" + questionNumber + ": " + questionString;
    }

    public void testContract() {
        // This function just returns a string to show that the contract is working.
        BlockchainRuntime.println("This contract is working.");
    }

    public static byte[] main() {
        return ABIDecoder.decodeAndRunWithClass(HelloAvm.class, BlockchainRuntime.getData());
    }
}

我不确定为什么它会失败,并且错误消息没有多大用处。我已经查看了StackOverflow上的其他InvocationTargetException错误,但它们似乎对解决这个问题没有帮助。

1 个答案:

答案 0 :(得分:1)

自己弄清楚。显然,您需要为Java合约创建每个函数static。因此上方的getQuestiontestContract应该看起来像这样:

public static String getQuestion() {
        return "Question #" + questionNumber + ": " + questionString;
    }

    public static void testContract() {
        // This function just returns a string to show that the contract is working.
        BlockchainRuntime.println("This contract is working.");
    }