c***@163.com
c***@163.com
  • 发布:2024-09-19 09:33
  • 更新:2024-09-20 00:30
  • 阅读:174

自己写了个uts插件,但是vue页面调用时报错,uts原生混编的方法

分类:uni-app

Error: java.lang.IllegalArgumentException: method uts.sdk.modules.mlcMdns.CallbackPair.<init> argument 1 has type kotlin.jvm.functions.Function1, got java.lang.Integer

自己开发的uts插件vue页面调用的时候报这个错误

报错
[Vue warn]: Error in v-on handler: "Error: java.lang.IllegalArgumentException: method uts.sdk.modules.mlcMdns.CallbackPair.<init> argument 1 has type kotlin.jvm.functions.Function1, got java.lang.Integer"

found in

Error: java.lang.IllegalArgumentException: method uts.sdk.modules.mlcMdns.CallbackPair.<init> argument 1 has type kotlin.jvm.functions.Function1, got java.lang.Integer

我不知道为啥会报这个错误

kotlin代码
package uts.sdk.modules.mlcMdns

import java.io.IOException
import javax.jmdns.JmDNS
import javax.jmdns.ServiceEvent
import javax.jmdns.ServiceListener

object MdnsDiscovery {
private lateinit var jmdns: JmDNS

fun startMdnsDiscovery(callback: CallbackPair) {
try {
jmdns = JmDNS.create()
callback.success("success")
} catch (e: IOException) {
callback.fail("error")
}
}

fun addServiceListener(listenerWrapper: ServiceListenerWrapper) {
jmdns.addServiceListener(listenerWrapper.serviceType, object : ServiceListener {
override fun serviceAdded(event: ServiceEvent?) {
listenerWrapper.onServiceAdded(event)
}
override fun serviceRemoved(event: ServiceEvent?) {
listenerWrapper.onServiceRemoved(event)
}
override fun serviceResolved(event: ServiceEvent?) {
listenerWrapper.onServiceResolved(event)
}
})
}

fun stopDiscovery(callback: CallbackPair) {
try {
if (::jmdns.isInitialized) {
jmdns.close()
callback.success("success")
} else {
callback.fail("error")
}
} catch (e: IOException) {
callback.success("success")
}
}
}

data class CallbackPair(
val success: (String) -> Unit,
val fail: (String) -> Unit
)

data class ServiceListenerWrapper(
val serviceType: String,
val onServiceAdded: (ServiceEvent?) -> Unit,
val onServiceRemoved: (ServiceEvent?) -> Unit,
val onServiceResolved: (ServiceEvent?) -> Unit
)

uts代码

import ServiceEvent from 'javax.jmdns.ServiceEvent';

export function startDiscovery(options: CallbackPair): void {
MdnsDiscovery.startMdnsDiscovery(options);
}

export function addServiceListener(options: ServiceListenerWrapper) {
MdnsDiscovery.addServiceListener(options);
}

export function stopDiscovery(options: CallbackPair): void {
MdnsDiscovery.stopDiscovery(options);
}

vue代码
startDiscovery({
success: function(response) {
console.log("start success");
addServiceListener({
serviceType: "_http._tcp.local.",
onServiceAdded: function(e) {
console.log("onServiceAdded", e);
},
onServiceRemoved: function(e) {
console.log("onServiceRemoved", e);
},
onServiceResolved: function(e) {
console.log("onServiceResolved", e);
}
});
setTimeout(function() {
stopDiscovery({
success: function(res) {
console.log("stop success");
},
error: function(err) {
console.log("stop error");
}
});
}, 6000);
},
fail: function(error) {
console.log("start error");
}
});

2024-09-19 09:33 负责人:DCloud_Android_DQQ 分享
已邀请:
DCloud_UNI_yuhe

DCloud_UNI_yuhe

你好,你可以尝试一下定位一下问题吗,提供一下相关代码?或者是提供一个测试工程

DCloud_Android_DQQ

DCloud_Android_DQQ

提供一下可以复现问题的示例。我看看

  • c***@163.com (作者)

    我想问问有没有快捷交流的方式?

    2024-09-19 15:49

  • c***@163.com (作者)

    代码我这不是已经给了吗

    2024-09-19 15:50

  • DCloud_Android_DQQ

    回复 c***@163.com: 你加我QQ 643833712

    2024-09-19 17:01

DCloud_heavensoft

DCloud_heavensoft

报问题应该按模板来,都看不出来你用的啥版本。注意混编是4.26才支持的

要回复问题请先登录注册