当我尝试从react本机模块调用函数时,它会将错误返回给我unknown:reactnative:catalystinstanceimpl捕获本机异常java.lang.runtimeexception:无法调用
如果我只是打印或控制模块方法中的某个东西,那么当我添加带有处理程序(looper)方法的实函数时,它就工作了,它抛出了错误
我下面的代码怎么了??或者我遗漏了什么?
这是我的本机模块类
package com.mosabeeapp;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.printer.sdk.PrinterConstants;
import com.printer.sdk.PrinterInstance;
import android.annotation.SuppressLint;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import java.io.File;
public class CalendarModule extends ReactContextBaseJavaModule {
public PrinterInstance myPrinter;
private String devicesName;
private String devicesAddress;
private Integer baudrate;
private Boolean isConnected;
private Handler mHandler = new Handler() {
@SuppressLint("ShowToast")
@Override
public void handleMessage(Message msg) {
System.out.println("@@@@@@@@@@@@" + msg.what);
switch (msg.what) {
case PrinterConstants.Connect.SUCCESS:
isConnected = true;
System.out.println("isConnected status:::;" + isConnected);
break;
case PrinterConstants.Connect.FAILED:
isConnected = false;
System.out.println("Connection failed");
break;
case PrinterConstants.Connect.CLOSED:
isConnected = false;
System.out.println("Connection closed");
break;
case PrinterConstants.Connect.NODEVICE:
System.out.println("There is no device");
isConnected = false;
break;
case 0:
System.out.println("0");
break;
case -1:
System.out.println("-1");
break;
case -2:
System.out.println("-2");
break;
case -3:
System.out.println("-3");
break;
default:
break;
}
}
};
CalendarModule(ReactApplicationContext context) {
super(context);
}
@Override
public String getName() {
return "CalendarModule";
}
@ReactMethod
public void printData(String data) {
System.out.println("----------buttonPrint--------");
devicesName = "Serial device";
devicesAddress = "/dev/ttyMT2";
String com_baudrate = "115200";
baudrate = Integer.parseInt(com_baudrate);
myPrinter = PrinterInstance.getPrinterInstance(new File(devicesAddress), baudrate,0,8, mHandler);
System.out.println("myPrinter.getCurrentStatus()-" + myPrinter.getCurrentStatus());
boolean b = myPrinter.openConnection();
System.out.println("-----------" + b);
if (b && myPrinter != null) {
System.out.println("Printer is ready");
} else {
System.out.println("Can not made a connection to the device");
}
}
}
这是我的全部错误
E/unknown:ReactNative: CatalystInstanceImpl caught native exception
java.lang.RuntimeException: Could not invoke CalendarModule.printData
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:383)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:223)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:223)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: library "libserial_port_sp.so" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
at java.lang.System.loadLibrary(System.java:1664)
at com.printer.sdk.serial.SerialPort.<clinit>(SerialPort.java:68)
at com.printer.sdk.PrinterInstance.<init>(PrinterInstance.java:143)
at com.printer.sdk.PrinterInstance.getPrinterInstance(PrinterInstance.java:153)
at com.mosabeeapp.CalendarModule.printData(CalendarModule.java:88)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:223)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:923)
E/unknown:ReactNative: Exception in native call
java.lang.RuntimeException: Could not invoke CalendarModule.printData
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:383)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:223)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:223)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:923)
Caused by: java.lang.UnsatisfiedLinkError: dlopen failed: library "libserial_port_sp.so" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
at java.lang.System.loadLibrary(System.java:1664)
at com.printer.sdk.serial.SerialPort.<clinit>(SerialPort.java:68)
at com.printer.sdk.PrinterInstance.<init>(PrinterInstance.java:143)
at com.printer.sdk.PrinterInstance.getPrinterInstance(PrinterInstance.java:153)
at com.mosabeeapp.CalendarModule.printData(CalendarModule.java:88)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:151)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:223)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:226)
at java.lang.Thread.run(Thread.java:923)
W/com.mosabeeapp: Accessing hidden method Landroid/graphics/FontFamily;-><init>()V (greylist-max-q, reflection, allowed)
Accessing hidden method Landroid/graphics/FontFamily;->addFontFromAssetManager(Landroid/content/res/AssetManager;Ljava/lang/String;IZIII[Landroid/graphics/fonts/FontVariationAxis;)Z (greylist-max-q, reflection, allowed)
Accessing hidden method Landroid/graphics/FontFamily;->addFontFromBuffer(Ljava/nio/ByteBuffer;I[Landroid/graphics/fonts/FontVariationAxis;II)Z (greylist-max-q, reflection, allowed)
Accessing hidden method Landroid/graphics/FontFamily;->freeze()Z (greylist-max-q, reflection, allowed)
Accessing hidden method Landroid/graphics/FontFamily;->abortCreation()V (greylist-max-q, reflection, allowed)
Accessing hidden method Landroid/graphics/Typeface;->createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (greylist, reflection, allowed)
E/unknown:ReactInstanceManager: destroyRootView called
E/unknown:ReactInstanceManager: destroyRootView called, unmountReactApplication
暂无答案!
目前还没有任何答案,快来回答吧!