Skip to content

Android "Cannot convert undefined or null to object" #16

@DeDuckProject

Description

@DeDuckProject

Hi,
I installed android following the instructions here.
When I try to do

let PayPal = require('react-native-paypal');

or

import PayPal from 'react-native-paypal';

I get this error:

Cannot convert undefined or null to object
<unknown>
    index.js:9
loadModuleImplementation
    require.js:122
guardedLoadModule
    require.js:65
_require
    require.js:49
<unknown>
    app.js:3
loadModuleImplementation
    require.js:122
guardedLoadModule
    require.js:65
_require
    require.js:49
<unknown>
    index.android.js:11
loadModuleImplementation
    require.js:122

My initial thought is that the code added to MainActivity contradicts the one in MainApplication.

The code added to main activity (followed the android setup):

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // ...
        payPalPackage = new PayPalPackage(this, PAY_PAL_REQUEST_ID); // <--

        ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index.android")
                .addPackage(new MainReactPackage())
                // ...
                .addPackage(payPalPackage) // <--
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();
        // ...
    }

    // ...

    @Override
    public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == PAY_PAL_REQUEST_ID) {
            payPalPackage.handleActivityResult(requestCode, resultCode, data); // <--
        } else {
//            otherModulesHandlers(requestCode, resultCode, data);
        }
    }

while the code which is in the MainApplication:

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    protected boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
              new ReactMaterialKitPackage(),
              new ReactNativePushNotificationPackage()
      );
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }
}

Seems to me like MainReactPackage is added twice. Am I right? What am I missing?

Thanks!
IY

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions