1

I am trying to learn how to write a react-native module, and I am getting stuck with this error:

enter image description here

Here is what my code looks like:

Module.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;

I have run both npm install and react-native link.

I have (for the most part) followed this tutorial.

4
  • Is RNGifMaker supposed to originate from NativeModules in file react-native.js or from a file called GifMaker.js? Commented Aug 5, 2017 at 22:36
  • It is supposed to originate form ../index.js Commented Aug 5, 2017 at 22:45
  • Then why import from GifMaker.js instead of from index.js in index.androud.js? Commented Aug 5, 2017 at 22:57
  • GifMaker.js does not exist. I am importing it form GifMaker which I set in package.json. Thanks for the help! Commented Aug 6, 2017 at 0:16

1 Answer 1

2

I figured it out! In Module.java I was returning the wrong class.

Was:

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

Should have been:

 public String getName() {
    return "RNGifMakerModule";
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.