当前位置: 首页 > 知识库问答 >
问题:

Java . lang . illegalargumentexception:无法在Corda中接收基元类型[int]

乐正浩博
2023-03-14

我试图使用recveAll()函数在PartyA(发起方)中接收有效负载。但是遇到了以下错误:

java.lang.IllegalArgumentException:执行流时无法接收基元类型[int]。

启动流程:

@InitiatingFlow
@StartableByRPC
class sendAllMapReceiveAll_IntExampleFlow(private val itemToBeSent : String,private val item2 : Int) : FlowLogic<String>(){
    @Suspendable
    override fun call():String {
        val counterParty1 = serviceHub.identityService.partiesFromName("PartyB",false).single()
        val counterParty2 = serviceHub.identityService.partiesFromName("PartyC",false).single()
        val counterPartySession1 = initiateFlow(counterParty1)
        val counterPartySession2 = initiateFlow(counterParty2)
        val sessionPayloadMap = mapOf(Pair(counterPartySession1,itemToBeSent), Pair(counterPartySession2,item2))
        sendAllMap(sessionPayloadMap)

        val receivedBack=receiveAll(Int::class.java, listOf(counterPartySession1,counterPartySession2)).map { it.unwrap { it } }

        return receivedBack.toString()
    }
}

响应程序流:

@InitiatedBy(sendAllMapReceiveAll_AnyExampleFlow::class)
class SendAllMapReceiveAllAnyResponder(private val counterSession : FlowSession): FlowLogic<Unit>(){
    @Suspendable
    override fun call(){
        val payloadItem  = counterSession.receive<Any>().unwrap { it }
        println("PayLoad Received at Responder = "+ payloadItem)
        counterSession.send(12346)
    }
}

后来为了解决这个错误。我发现这个链接很有帮助。通过在receiveAll()中将Int改为Integer,解决了这个问题。但是int在单接收函数中工作,如下所示:

val payloadItem  = counterSession.receive<Int>().unwrap { it }
  1. 为什么primitive int在receiveAll()中不工作,但同时在单个receive(session)中工作
  2. kotlin中的其他基元类型在receiveAll()中的行为也类似吗

编辑:再添加一个例子,给我同样的错误来解决答案中的混淆。

val receivedBack2 =receiveAllMap(mapOf(Pair(counterPartySession1,String::class.java),
                Pair(counterPartySession2,Int::class.java))).map { it.value.unwrap { it } }

共有1个答案

王才英
2023-03-14

我认为您提供的代码片段不准确。
错误消息清楚地提到您尝试接收原始int(小写i);而在您的代码中,您编写了类Int(大写I)。

我认为最初你的代码中有int,你得到了那个错误,然后在发布问题时把它改成了Int

send()receive()sendAndReceive()仅适用于类(请参阅此处的文档);因此它将与IntInteger一起使用;它不能与int一起使用。

 类似资料:
  • 我已经创建了一个交易对手会话,发行方通过将其密钥传递给signLaunalTransaction来签署交易。然后,当我调用CollectSignaturesFlow以获取买方签名时,它会抛出“无法匹配密钥”异常。 不知道出了什么问题。 这是我的发起流。

  • 请参阅输出。。 问题在于Demo类中的方法“receive(Object temp)”如何接收基元整型数组的基址。 如果对象类引用变量可以接收基元类型数组基址,那么有一点很清楚,基址必须是对象类类型或对象类类型的子类。。 那么,是否也存在用于基元类型数组地址的类?

  • 我一直在尝试移植一段JavaScript代码,现在,我唯一尚未开始工作的部分出现了此错误:无法在原始类型int上调用padLz(int)。原始JavaScript代码在下面,同样是我的移植版本,我还无法工作的部分还突出显示。 错误: 无法在基元类型 int 上调用 padLz(int) 原件 移植版本 string grid ref = let pair ' ' e . padlz(digits/

  • 我有一个写日志到HDFS的Flume-ng。 我在一个节点中做了一个代理。 但是它没有运行。 这是我的配置。 #示例2.conf:单节点水槽配置 #命名这个代理上的组件 agent1.sources=源1 agent1.sinks=sink1 agent1.channels=channel1 agent1.sources.source1.type=avro agent1.sources.sourc

  • 我想创建如下界面: 然后我们可以将它用于一个新类: 我想对s做同样的事情。在纯JavaScript中,我可以使类型,例如,满足以下接口: 但TypeScript不允许我这样做: 有办法做到这一点吗?