java - 调用目标异常 : Dapp call failed when using Aion Embedded AVM

标签 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]

我刚刚编辑了 mvn 初始化 项目时获得的 HelloAvM 合约。这是整个契约(Contract):

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 上的其他 InvocableTargetException 错误,但它们似乎对解决此问题没有帮助。

最佳答案

我自己想出来了。显然,您需要将 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.");
    }

关于java - 调用目标异常 : Dapp call failed when using Aion Embedded AVM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55289368/

相关文章:

java - 显示 Aion 账户的余额

java - Corda V4模板应用程序在运行deployNodes时崩溃

ios - 在 Xcode 中发送交易时收到 "configurationError"

java - 合约编译因 InvoicationTargetException 错误而失败

Java SDK HyperLedger Fabric

java - 如何配置 Spring 以尽可能多地节省内存?

java - 将文本插入生成的 pdf 文档

java - 如何使用每行 lambda/流对 2D 列表进行排序?

java - 在 Selenium 测试中指定自定义屏幕分辨率