2017-06-13 59 views
0

我正在使用React Native開發Android應用程序。我嘗試運行一個正在顯示的屏幕的簡單代碼,但我得到以下error。我嘗試關閉所有的命令行窗口和模擬器,並重新啓動React Native軟件包並運行它,但不起作用。該代碼下面提供:開發服務器返回響應錯誤代碼:500 - 反應原生

index.android.js:

import React, { Component} from 'react'; 
import {Text, View, AppRegistry,Button} from 'react-native'; 
import {StackNavigator} from 'react-navigation'; 

import dhrumil from '.\dhrumil.js'; 

export default class MainApp extends Component{ 
render(){ 
    return(
    <dhrumil /> 
); 
} 

} 

const SimpleApp = StackNavigator({ 
    Home: {screen: dhrumil } 
}); 


AppRegistry.registerComponent("MainApp",()=>SimpleApp); 

dhrumil.js:

import React, { Component} from 'react'; 
import {Text, View, AppRegistry,Button,StyleSheet} from 'react-native'; 

const dhrumil =() =>{ 

    return(
    <View style={styles.container}> 
    <Text style={styles.texter}>Hello World!</Text> 
    <Button 
     onPress={() => navigate('dharmin')} 
     title="Chat with Lucy" 
     /> 
     </View> 
); 
} 

const styles = StyleSheet.create({ 
    container:{ 
    justifyContent: 'center', 
    alignItems: 'center', 
    flex: 1 
    } 
    texter: 
    { 
    fontSize: 20, 
    textAlign: 'center' 
    } 
}); 


dhrumil.navigationOptions = { 
    title:'dhrumil' 
} 
export default dhrumil 

如何解決這個問題?

回答

1

index.android.jsimport dhrumil from '.\dhrumil.js';更改爲import dhrumil from './dhrumil';。您必須使用/指定路徑,並且在導入js文件時不需要使用dhrumil.js

+0

是的,我剛剛發現這個錯誤。這是一個愚蠢的錯誤。謝了哥們! –

0

@Jeffrey Rajan的建議在這裏是絕對正確的。

多發生因這個錯誤: 問題1:

  1. 一個錯誤的文件名import語句
  2. 使用文件名
  3. 錯誤的情況下使用「\」,而不是「/」在文件名中

希望使用此列表可以輕鬆找到在代碼中導致此錯誤的錯誤。

問題2: 的用料問題design.To解決此本地安裝材料設計使用:

react-native-material-design

問題3: 通天預設反應的本地製造麻煩的代碼。要解決此問題,請執行以下操作:

yarn remove babel-preset-react-native 

yarn add [email protected] 

請嘗試按此順序排除故障。最重要的是,問題1將解決問題。

+0

嗨,如果您遇到任何問題,請在列表中建議更多項目。我列出了迄今爲止遇到的所有問題,以及我如何修復它們。 –

相關問題