gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:06:45 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com