0

当我使用 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]

我刚刚编辑了HelloAvMmvn 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 错误,但它们似乎对这个问题没有帮助。

4

1 回答 1

1

我自己想通了。显然,您需要static为 Java 合约创建每个函数。所以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.");
    }
于 2019-03-26T14:56:07.880 回答