gpt4 book ai didi

Android undefined 不是评估自定义模块的对象 - React Native

转载 作者:行者123 更新时间:2023-11-29 19:10:35 24 4
gpt4 key购买 nike

我正在尝试学习如何编写一个 react-native 模块,但我遇到了这个错误:

enter image description here

这是我的代码:

模块.java (../android/src/main/java/com/reactlibrary)

public class RNGifMakerModule extends ReactContextBaseJavaModule {

private final ReactApplicationContext reactContext;

public RNGifMakerModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}

@Override
public String getName() {
return "RNGifMaker";
}

@ReactMethod
public void alert(String message) {
Toast.makeText(getReactApplicationContext(), message, Toast.LENGTH_LONG).show();
}
}

index.android.js

import { RNGifMaker } from 'GifMaker';

const onButtonPress = () => {
RNGifMaker.alert('Hello World');
};

package.json

"dependencies": {
"react": "16.0.0-alpha.6",
"react-native": "0.43.3",
"GifMaker":"file:../"
},

index.js (../)

import { NativeModules } from 'react-native';

module.exports = NativeModules.RNGifMaker;

我已经运行了 npm installreact-native link

我(大部分)关注了 this tutorial .

最佳答案

我想通了!在 Module.java 中,我返回了错误的类。

是:

public String getName() {
return "RNGifMaker";
}

应该是:

 public String getName() {
return "RNGifMakerModule";
}

关于Android undefined 不是评估自定义模块的对象 - React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45526683/

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