使用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错误,但它们似乎对解决这个问题没有帮助。
最佳答案
我自己想通了。显然,您需要为Java合约创建每个函数static
。因此,上面的getQuestion
和testContract
应该看起来像这样:
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.");
}