我无法执行官方网站上的示例支付查询程序。这是我的代码,与示例几乎相同。这里是官方网站.
public class TransCheck {
public static void main(String args[]) {
Server server = new Server("https://horizon-testnet.stellar.org");
KeyPair account = KeyPair.fromAccountId("GARUMRUP37CPOGQQALSXBDQQS6SUDDPKGLGFERH6PIJEHWQY5IAVZQDL");
// Create an API call to query payments involving the account.
// server.payments() Returns PaymentsRequestBuilder instance.
// forAccount() Builds request to GET /accounts/{account}/payments - Account for which to get payments
PaymentsRequestBuilder paymentsRequest = server.payments().forAccount(account);
// If some payments have already been handled, start the results from the
// last seen payment. (See below in `handlePayment` where it gets saved.)
String lastToken = loadLastPagingToken();
if (lastToken != null) {
paymentsRequest.cursor(lastToken);
}
// `stream` will send each recorded payment, one by one, then keep the
// connection open and continue to send you new payments as they occur.
paymentsRequest.stream(new EventListener <OperationResponse>(){
@Override
public void onEvent(OperationResponse payment) {
// Record the paging token so we can start from here next time.
savePagingToken(payment.getPagingToken());
// The payments stream includes both sent and received payments. We only
// want to process received payments here.
if (payment instanceof PaymentOperationResponse) {
if (((PaymentOperationResponse) payment).getTo().equals(account)) {
return;
}
String amount = ((PaymentOperationResponse) payment).getAmount();
Asset asset = ((PaymentOperationResponse) payment).getAsset();
String assetName;
if (asset.equals(new AssetTypeNative())) {
assetName = "lumens";
} else {
StringBuilder assetNameBuilder = new StringBuilder();
assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getCode());
assetNameBuilder.append(":");
assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getIssuer().getAccountId());
assetName = assetNameBuilder.toString();
}
StringBuilder output = new StringBuilder();
output.append(amount);
output.append(" ");
output.append(assetName);
output.append(" from ");
output.append(((PaymentOperationResponse) payment).getFrom().getAccountId());
System.out.println(output.toString());
}
}
});
}
}
我的代码中有两个错误。一、方法:loadLastPagingToken()
未定义,我找不到该方法的详细信息。其次,当我想创建一个new EventListener <OperationResponse>()
IDE 告诉我们
EventListener 类型不是通用的;它不能用参数参数化
我真不知道为什么。请你帮助我好吗?谢谢。
这是因为你的导入声明。
Try
导入 org.stellar.sdk.requests.EventListener;
代替
导入 java.util.EventListener;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)