Skip to content

Error:Java exception in 'NativeModules' java.lang.RuntimeException: Got unknown argument class: Info #24287

@ko-devHong

Description

@ko-devHong

🐛 Bug Report

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

To Reproduce

In the 'Manager.java' file, you can 'import' the 'Info.java' file and try it as a return type.

Expected Behavior

I'd like to use the class 'Info' as a type.

Code Example

Info.java:

package com.control;

import android.widget.Toast;

import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.Map;
import java.util.HashMap;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class Info extends ReactContextBaseJavaModule implements Serializable, Parcelable {
private static final String DURATION_SHORT_KEY = "SHORT";
    private static final String DURATION_LONG_KEY = "LONG";

public Info(ReactApplicationContext reactContext) {
        super(reactContext);
    }
@Override
    public String getName() {
        return "Info";
    }

private String Type = "";

@ReactMethod(isBlockingSynchronousMethod = true)
    public String getType() {
        return Type;
    }

    @ReactMethod
    public void setType(String Type) {
        this.Type = Type;
    }
...
@Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(Type);
    }

public static final Creator<Info> CREATOR = new Creator<Info>() {
        public Info createFromParcel(Parcel in) {
            return new Info(in);
        }

        public Info[] newArray(int size) {
            return new Info[size];
        }
    };

public Info(Parcel in) {
        super(null);
        coinType = in.readString();
    }
}

Manager.java:

package com;

import android.widget.Toast;
import android.content.Context;

import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;

import com.control.Info;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.RealmMigration;

import java.util.Map;
import java.security.Security;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Manager extends ReactContextBaseJavaModule {
private static final String DURATION_SHORT_KEY = "SHORT";
    private static final String DURATION_LONG_KEY = "LONG";

private ReactApplicationContext mReactContext;

public Manager(ReactApplicationContext reactContext) {
        super(reactContext);
        mReactContext = reactContext;
    }
@Override
    public String getName() {
        return "Manager";
    }
...
private Info info;

@ReactMethod(isBlockingSynchronousMethod = true)
public Info getInfo() {
        return info;
    }
...
}

App.js

import React, { Component } from "react";
import { StyleSheet, Text, View, NativeModules } from "react-native";

const { Manager, Info } = NativeModules;

export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentWillMount() {
    manager = new Manager();
    manager.getInfo();
  }

  render() {
    return (
      <View style={styles.container}>
        <Text>Test</Text>
      </View>
    );
  }
}

Environment

React Native Environment Info:
System:
OS: MacBook Pro (Retina, 13-inch, Late 2012)
CPU: 2.5 GHz Intel Core i5
Memory: 8GB 1600 MHz DDR3
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.10.0 - ~/.nvm/versions/node/v8.10.0/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 5.6.0 - ~/.nvm/versions/node/v8.10.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Android SDK:
API Levels: 25, 26, 27, 28
Build Tools: 23.0.1, 23.0.2, 23.0.3, 24.0.2, 25.0.0, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.3, 28.0.2, 28.0.3
IDEs:
Android Studio: 3.3.2
npmPackages:
react: "16.5.0",
react-native: "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz"

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugStaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions