错误:null不是对象(评估"C.State")< unknown> index.android.bundle [英] Error: null is not an object (evaluating 'C.State') <unknown> index.android.bundle
问题描述
我是React-Native的新手.我正在将现有的Android本机应用程序与react本机应用程序集成在一起. 运行应用程序后的react native部分显示此错误:
null不是对象(评估"C.State") 未知的 index.android.bundle
这是错误的屏幕截图: 错误消息的屏幕截图
我知道每次我使用 react-navigation 和 react-native-gesture-handler 时都会出现此错误消息.
这是package.json文件的代码:
{
"name": "Demo",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.6.3",
"react-native": "^0.58.3",
"react-native-gesture-handler": "^1.0.15",
"react-navigation": "^3.1.4"
},
"devDependencies": {
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "24.0.0",
"jest": "24.0.0",
"metro-react-native-babel-preset": "0.51.1",
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native"
}
}
这是呈现react-native模块的本机活动:
public class MyReactActivity extends Activity implements DefaultHardwareBackBtnHandler {
private ReactRootView mReactRootView;
private ReactInstanceManager mReactInstanceManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModulePath("index.android")
.addPackage(new MainReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
Bundle initialProps = new Bundle();
String str = MainActivity.getMovieID();
initialProps.putString("movie_id", str);
mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", initialProps);
setContentView(mReactRootView);
}
观察上面代码中编写的index.android.bundle.
在运行应用程序之前,我还运行以下命令来解析解决方案
我有一个类似的问题,我做了什么解决,它是阅读React Navigation文档,在此页面中,这是我的解决方案: >
https://reactnavigation.org/docs/en/getting-started.html
在那之后,如果您的settings.gradle文件中出现如下错误:
失败:构建失败,并出现异常.
- 位置:
设置文件'C:\ PATH \ TO \ YOUR \ PROYECT \ android \ settings.gradle'行:3 ...
在您的settings.gradle文件中,在您看到以下内容的行中将这些字符"\"更改为该"/":'.. \ node_modules \ react-native-gesture-handler \ android'
就是这样,希望我能为您提供帮助...
I am new to React-Native. I was integrating my existing Android native app with react native app. The react native part after running app is showing this error:
null is not an object (evaluating 'C.State') unknown index.android.bundle
Here is the screenshot of the error: Screenshot of error message
I know that this error message comes every time I use react-navigation and react-native-gesture-handler.
Here is the code for package.json file:
{
"name": "Demo",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.6.3",
"react-native": "^0.58.3",
"react-native-gesture-handler": "^1.0.15",
"react-navigation": "^3.1.4"
},
"devDependencies": {
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "24.0.0",
"jest": "24.0.0",
"metro-react-native-babel-preset": "0.51.1",
"react-test-renderer": "16.6.3"
},
"jest": {
"preset": "react-native"
}
}
Here is the native activity that renders the react-native module:
public class MyReactActivity extends Activity implements DefaultHardwareBackBtnHandler {
private ReactRootView mReactRootView;
private ReactInstanceManager mReactInstanceManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModulePath("index.android")
.addPackage(new MainReactPackage())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
Bundle initialProps = new Bundle();
String str = MainActivity.getMovieID();
initialProps.putString("movie_id", str);
mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", initialProps);
setContentView(mReactRootView);
}
Observe the index.android.bundle written in above code.
Also before running the app I run this command to resolve the Unable to load script from assets index.android.bundle
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
Here too observe that something is being done at index.android.bundle
Can't find anything related to this error. Any help will be appreciated. Thanks.
I had a similar problem, what I did to fix it, it was to read the React Navigation documentation, in this page it is my solution:
https://reactnavigation.org/docs/en/getting-started.html
After that, if you have an error in your settings.gradle file that says something like this:
FAILURE: Build failed with an exception.
- Where:
Settings file 'C:\PATH\TO\YOUR\PROYECT\android\settings.gradle' line: 3...
In your settings.gradle file, change these characters "\" for this one "/" in the line where you see this: '..\node_modules\react-native-gesture-handler\android'
And that's it, hope I was able to help...
这篇关于错误:null不是对象(评估"C.State")< unknown> index.android.bundle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!