I'm currently creating a 'react-native module'.
I'm referring to this.
I'm trying to create and apply a module, but there's a problem with the function.
Info.java:
packagecom.control;
importandroid.widget.Toast;
importcom.facebook.react.bridge.NativeModule;
importcom.facebook.react.bridge.ReactApplicationContext;
importcom.facebook.react.bridge.ReactContext;
importcom.facebook.react.bridge.ReactContextBaseJavaModule;
importcom.facebook.react.bridge.ReactMethod;
importandroid.os.Parcel;
importandroid.os.Parcelable;
importjava.util.Map;
importjava.util.HashMap;
importjava.io.Serializable;
importjava.util.ArrayList;
importjava.util.List;
publicclassInfoextendsReactContextBaseJavaModuleimplementsSerializable, Parcelable {
privatestaticfinalStringDURATION_SHORT_KEY = "SHORT";
privatestaticfinalStringDURATION_LONG_KEY = "LONG";
publicInfo(ReactApplicationContextreactContext) {
super(reactContext);
}
@OverridepublicStringgetName() {
return"Info";
}
privateStringType = "";
@ReactMethod(isBlockingSynchronousMethod = true)
publicStringgetType() {
returnType;
}
@ReactMethodpublicvoidsetType(StringType) {
this.Type = Type;
}
...
@OverridepublicvoidwriteToParcel(Parceldest, intflags) {
dest.writeString(Type);
}
publicstaticfinalCreator<Info> CREATOR = newCreator<Info>() {
publicInfocreateFromParcel(Parcelin) {
returnnewInfo(in);
}
publicInfo[] newArray(intsize) {
returnnewInfo[size];
}
};
publicInfo(Parcelin) {
super(null);
coinType = in.readString();
}
}Manager.java:
packagecom;
importandroid.widget.Toast;
importandroid.content.Context;
importcom.facebook.react.bridge.NativeModule;
importcom.facebook.react.bridge.ReactApplicationContext;
importcom.facebook.react.bridge.ReactContext;
importcom.facebook.react.bridge.ReactContextBaseJavaModule;
importcom.facebook.react.bridge.ReactMethod;
importcom.facebook.react.bridge.ReadableMap;
importcom.control.Info;
importio.realm.Realm;
importio.realm.RealmConfiguration;
importio.realm.RealmMigration;
importjava.util.Map;
importjava.security.Security;
importjava.util.ArrayList;
importjava.util.HashMap;
importjava.util.List;
publicclassManagerextendsReactContextBaseJavaModule {
privatestaticfinalStringDURATION_SHORT_KEY = "SHORT";
privatestaticfinalStringDURATION_LONG_KEY = "LONG";
privateReactApplicationContextmReactContext;
publicManager(ReactApplicationContextreactContext) {
super(reactContext);
mReactContext = reactContext;
}
@OverridepublicStringgetName() {
return"Manager";
}
...
privateInfoinfo;
@ReactMethod(isBlockingSynchronousMethod = true)
publicInfogetInfo() {
returninfo;
}
...
}App.js
importReact,{Component}from"react";import{StyleSheet,Text,View,NativeModules}from"react-native";const{ Manager, Info }=NativeModules;exportdefaultclassAppextendsReact.Component{constructor(props){super(props);this.state={};}componentWillMount(){manager=newManager();manager.getInfo();}render(){return(<Viewstyle={styles.container}><Text>Test</Text></View>);}}As you can see, I'm going to use the argument type of the function as Info.
However, as you can see below 'error code', the error occur.
Java exception in 'NativeModules'
java.lang.RuntimeException: Got unknown argument class: Info
com.facebook.react.bridge.JavaMethodWrapper.buildArgumentExtractors ...
How can I use 'Info' as an argument type? Please help me a lot.
I'm currently creating a 'react-native module'.
I'm referring to this.
I'm trying to create and apply a module, but there's a problem with the function.
Info.java:
Manager.java:
App.js
As you can see, I'm going to use the argument type of the function as Info.
However, as you can see below 'error code', the error occur.
How can I use 'Info' as an argument type? Please help me a lot.