InvocationTargetException:使用 Aion Embedded AVM 时 Dapp 调用失败
InvocationTargetException: Dapp call failed when using Aion Embedded AVM
当我使用 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 initialize
项目时获得的 HelloAvM
合同。这是整个合同:
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());
}
}
我不确定为什么会失败,错误消息也没什么用。我查看了 Whosebug 上的其他 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.");
}
当我使用 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 initialize
项目时获得的 HelloAvM
合同。这是整个合同:
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());
}
}
我不确定为什么会失败,错误消息也没什么用。我查看了 Whosebug 上的其他 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.");
}