2017-06-06 69 views
0

我正在使用react-native框架來開發我的小android應用程序。我試圖從index.android.js.when重定向到Home.js,當我運行它時,它顯示我的紅色錯誤消息模擬器返回響應錯誤500反應本機

index.android.js

import React, { Component } from 'react'; 
import {AppRegistry,Text,View} from 'react-native'; 
import Home from 'App/Component/Home'; 

export default class mylApp extends Component { 
    render() { 
    return (
     <View> 
     <Home /> 
     </View> 
    ); 
    } 
} 

AppRegistry.registerComponent('reactTutorialApp',() => reactTutorialApp); 

Home.js

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


class Home extends Component { 
    state = { 
     myTxt: 'hiiiiiiiiiiiiiiiiiiiiiii'; 
    } 

    render() { 
     return (
     <View> 
      <Text> 
       {this.state.myTxt} 
      </Text> 
     </View> 
    ); 
    } 
} 

export default Home; 

enter image description here

回答

1

請檢查此導入路徑import Home from 'App/Component/Home';。我假設Home.js在項目(文件夾) - >應用程序(文件夾) - >組件(文件夾) - > Home.js中。如果是這樣,那麼你需要導入這樣import Home from './App/Component/Home';

更新1:

index.android.js

import React, { Component } from 'react'; 
import {AppRegistry,Text,View} from 'react-native'; 
import Home from './App/Component/Home'; 

export default class mylApp extends Component { 
    render() { 
    return (
     <View> 
     <Home /> 
     </View> 
    ); 
    } 
} 

AppRegistry.registerComponent('reactTutorialApp',() => mylApp); 

更新2

Home.js

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


class Home extends Component { 
    state = { 
     myTxt: 'hiiiiiiiiiiiiiiiiiiiiiii' 
    } 

    render() { 
     return (
     <View> 
      <Text> 
       {this.state.myTxt} 
      </Text> 
     </View> 
    ); 
    } 
} 

export default Home; 
+0

現在它顯示'意外的令牌,預計,(6:24) 在C:\用戶\ Yasiru \ AndroidStudioProjects \新建文件夾\ reactTutorialApp \軟件\組件\ Home.js' – Tje123

+0

仍然相同error.'Unexpected令牌,預計,' – Tje123

+0

是的,我已經替換爲您code.but兩個指數和家庭JS它的顯示意外的標記在home.js文件 – Tje123