java.lang.NullPointerException at org.web3j.protocol.core.fi



我正在尝试使用web3j读取区块链事件(在Java中),但获得NPE:

java.lang.NullPointerException: null
at org.web3j.protocol.core.filters.LogFilter.process(LogFilter.java:46)
at org.web3j.protocol.core.filters.Filter.getInitialFilterLogs(Filter.java:119)
at org.web3j.protocol.core.filters.Filter.run(Filter.java:69)
at org.web3j.protocol.rx.JsonRpc2_0Rx.run(JsonRpc2_0Rx.java:89)
at org.web3j.protocol.rx.JsonRpc2_0Rx.lambda$ethLogFlowable$2(JsonRpc2_0Rx.java:79)
at io.reactivex.internal.operators.flowable.FlowableCreate.subscribeActual(FlowableCreate.java:71)
at io.reactivex.Flowable.subscribe(Flowable.java:14935)
at io.reactivex.Flowable.subscribe(Flowable.java:14872)
at io.reactivex.Flowable.subscribe(Flowable.java:14791)

问题代码

(EthLog

。LogResult: LogResult) {https://github.com/web3j/web3j/blob/master/core/src/main/java/org/web3j/protocol/core/filters/LogFilter.java L46

@Override
protected void process(List<EthLog.LogResult> logResults) {
for (EthLog.LogResult logResult : logResults) {
if (logResult instanceof EthLog.LogObject) {
Log log = ((EthLog.LogObject) logResult).get();
callback.onEvent(log);
} else {
throw new FilterException(
"Unexpected result type: " + logResult.get() + " required LogObject");
}
}
}

提出问题https://github.com/web3j/web3j/issues/1486但由于没有预料到它会被修复,我该怎么办呢?

  • 示例代码和/或代码片段
private void createEventMonitor() {
log.info("createEventMonitor() begin...");
// contract from block
EthFilter filter = new EthFilter(DefaultBlockParameter.valueOf(new BigInteger("7605105")),
DefaultBlockParameterName.LATEST, contractAddress);
//Disposable subscription
subscription = web3j
.ethLogFlowable(filter)
.subscribe(
event -> {
log.info("Withdraw event received:");
log.info("  event data >>> {}", event.getData());
log.info("  event topic >>> {}", event.getTopics().stream().collect(Collectors.joining()));
log.info("  event address >>> {}", event.getAddress());
log.info("  event txHash >>> {}", event.getTransactionHash());
}, error -> {
log.error("Event error: {}", error, error); //!
});
log.info("createEventMonitor() end.");
}

在https://github.com/web3j/web3j/pull/1495解决https://github.com/web3j/web3j/issues/1486(应该是4.8.7之后的下一个版本)之后这个错误应该会消失

简而言之:JSON RPC错误在web3j级别不可见。

分析类似的问题,运行日志级别为debug的程序来查看JSON RPC消息。

相关内容

  • 没有找到相关文章

最新更新