beefe / react-native-picker

A Native Picker with high performance.
1.75k stars 785 forks source link

About android platform error : undefined is not an object (evaluating 'Picker._init') #108

Open shexiaoheng opened 7 years ago

shexiaoheng commented 7 years ago

If this error occurs, please refer to this wiki first , or view this issues #98 Do not open new issues ! Thanks !

JusticeLai commented 7 years ago

Native iOS jump to ReactNative then push pick correct, ReactNative push pick is correct, Native Android jump to ReactNative then push pick err, image

JusticeLai commented 7 years ago

Version

react-native-picker v4.0.16 react-native v0.40

Platform

1.AndroidManifest.xml add permission 2.addPackage(newImagePickerPackage())----in ReactNative Activity 3.settings.gradle add some code 4.build.gradle add some code 5.and rebuild the project

6Android hava a button ,then jump to ReactNative Activity(if only ReactNative is ok,to show picker)

7.In ReactNative Activity click a button,to show this -picker

8.The steps are the same, but other components can

image @shexiaoheng

shexiaoheng commented 7 years ago

测试过了,没有发现你说的问题。 只要是 undefined is not an object (evaluating 'Picker._init') 这个错误,没有别的,一定是组件没有引入成功,参考 #98 第7条回复

JusticeLai commented 7 years ago

@shexiaoheng 大神你看看我是安卓项目下集成你的组件,然后点击不显示,如果是纯ReactNative就可以显示..

shexiaoheng commented 7 years ago

检查下面的这些文件:

private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override protected List getPackages() { return Arrays.asList( new MainReactPackage(), new PickerViewPackage() // Added there ); } };

JusticeLai commented 7 years ago

@shexiaoheng 1. image

2.image 3. image

4,纯RN就可以,但是我的是安卓里面有一个入口点击进入RN,就不行了..其他的第三方组件有些可以有些不可以

shexiaoheng commented 7 years ago
@Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                new MainReactPackage(),
                new PickerViewPackage()          // Added there
            );
        }

这个文件在哪里

JusticeLai commented 7 years ago

@shexiaoheng 有没有QQ或者微信搞搞聊聊啊大神 这个是全局应用..我加了也没用的 image

shexiaoheng commented 7 years ago

react-native: v0.40 不会出现你的这些代码: image

应该是这样的:

public class ShowAty extends ReactActivity { // 你的类名

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "PickerTest"; // 你的项目的名字
    }
}
JusticeLai commented 7 years ago

@shexiaoheng image 还是不行

shexiaoheng commented 7 years ago

? 我说的是下面的这些代码是不应该出现的 image

JusticeLai commented 7 years ago

那我怎么跳转到ReactNative入口界面...我现在安卓项目集成ReactNative...不是纯ReactNative

shexiaoheng commented 7 years ago

参考下我写的例子:

MainActivity.java

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        RelativeLayout layout = new RelativeLayout(this);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT
        );
        layout.setLayoutParams(params);
        Button button = new Button(this);
        button.setText("点击跳转");
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT
        );
        lp.addRule(RelativeLayout.CENTER_IN_PARENT);
        button.setLayoutParams(lp);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(MainActivity.this, ShowAty.class));
                finish();
            }
        });
        layout.addView(button);
        setContentView(layout);
    }
}

MainApplication.java

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 PickerViewPackage()
            );
        }
    };

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

    @Override
    public void onCreate() {
        super.onCreate();
        SoLoader.init(this, /* native exopackage */ false);
    }
}

ShowAty.java

public class ShowAty extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "PickerTest";
    }
}
shexiaoheng commented 7 years ago

也就是你用react-native init project_name创建完项目后,新建一个类,把原来MainActivity的代码移过去,在新创建的类里面去做你本地要做的事

JusticeLai commented 7 years ago

我再试试.谢谢

weijianfeng commented 7 years ago

如果是iOS使用这个控件,也需要在 native的配置中,写额外的东西么。

chaoming007 commented 6 years ago

@shexiaoheng 朋友求帮解决一下我ios 出现了 “Cannot read property '_init' of undefined” ,不知道如何解决