gpt4 book ai didi

java - 从 Xamarin 中的 Java 绑定(bind)库接口(interface)访问属性

转载 作者:太空宇宙 更新时间:2023-11-04 12:28:57 24 4
gpt4 key购买 nike

当我尝试从 Java.Lang.Object 获取 X 时,出现 AbstractMethodError。

class DataMessageHandler : Java.Lang.Object, IRouteManagerMessageHandler
{
public void Process(Message p0)
{
var message = p0;
var cartesian = Class.FromType(typeof(CartesianFloat));

var value = (ICartesian)message.GetData(cartesian);
var x = value.X();
}
}

其中 CartesianFloat 是 ICartesian 的实现。

笛卡尔:

[global::Java.Interop.JavaTypeParameters (new string [] {"T extends java.lang.Number"})]
public partial interface ICartesian : IJavaObject {

// Metadata.xml XPath method reference: path="/api/package[@name='com.mbientlab.metawear.data']/interface[@name='Cartesian']/method[@name='x' and count(parameter)=0]"
[Register ("x", "()Ljava/lang/Number;", "GetXHandler:Com.Mbientlab.Metawear.Data.ICartesianInvoker, MetaWearAndroid")]
global::Java.Lang.Object X ();

// Metadata.xml XPath method reference: path="/api/package[@name='com.mbientlab.metawear.data']/interface[@name='Cartesian']/method[@name='y' and count(parameter)=0]"
[Register ("y", "()Ljava/lang/Number;", "GetYHandler:Com.Mbientlab.Metawear.Data.ICartesianInvoker, MetaWearAndroid")]
global::Java.Lang.Object Y ();

// Metadata.xml XPath method reference: path="/api/package[@name='com.mbientlab.metawear.data']/interface[@name='Cartesian']/method[@name='z' and count(parameter)=0]"
[Register ("z", "()Ljava/lang/Number;", "GetZHandler:Com.Mbientlab.Metawear.Data.ICartesianInvoker, MetaWearAndroid")]
global::Java.Lang.Object Z ();

}

笛卡尔 float :

        public unsafe CartesianFloat ()
: base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
{
if (Handle != IntPtr.Zero)
return;

try {
if (GetType () != typeof (CartesianFloat)) {
SetHandle (
global::Android.Runtime.JNIEnv.StartCreateInstance (GetType (), "()V"),
JniHandleOwnership.TransferLocalRef);
global::Android.Runtime.JNIEnv.FinishCreateInstance (Handle, "()V");
return;
}

if (id_ctor == IntPtr.Zero)
id_ctor = JNIEnv.GetMethodID (class_ref, "<init>", "()V");
SetHandle (
global::Android.Runtime.JNIEnv.StartCreateInstance (class_ref, id_ctor),
JniHandleOwnership.TransferLocalRef);
JNIEnv.FinishCreateInstance (Handle, class_ref, id_ctor);
} finally {
}
}

// This method is explicitly implemented as a member of an instantiated Com.Mbientlab.Metawear.Data.ICartesian
global::Java.Lang.Object global::Com.Mbientlab.Metawear.Data.ICartesian.X ()
{
return global::Java.Interop.JavaObjectExtensions.JavaCast<Java.Lang.Object>(((ICartesian) this).X ());
}

// This method is explicitly implemented as a member of an instantiated Com.Mbientlab.Metawear.Data.ICartesian
global::Java.Lang.Object global::Com.Mbientlab.Metawear.Data.ICartesian.Y ()
{
return global::Java.Interop.JavaObjectExtensions.JavaCast<Java.Lang.Object>(((ICartesian) this).Y ());
}

// This method is explicitly implemented as a member of an instantiated Com.Mbientlab.Metawear.Data.ICartesian
global::Java.Lang.Object global::Com.Mbientlab.Metawear.Data.ICartesian.Z ()
{
return global::Java.Interop.JavaObjectExtensions.JavaCast<Java.Lang.Object>(((ICartesian) this).Z ());
}

}

如果我尝试将值转换为 CartesianFloat,它会说值上不存在方法 X()。

将 watch 置于值(value)上,其值为 {(-0.062, 0.070, 1.010)}

最佳答案

Metwear API 在 BLE 数据包中发送编码数据,您可以使用以下代码对其进行解码。我从他们的 java 代码中翻译了它(而不是优化)。

public void Process(Message p0)
{
var message = p0 as Bmi160ThreeAxisMessage;
var data = message.GetData();
var x = ((short)(data[1] << 8 | data[0])) / message.Scale;
var y = ((short)(data[3] << 8 | data[2])) / message.Scale;
var z = ((short)(data[5] << 8 | data[4])) / message.Scale;
}

关于java - 从 Xamarin 中的 Java 绑定(bind)库接口(interface)访问属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38075551/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com