2017-07-19 18 views
1

我學習react-native,我跑來到這個疑難問題有一個類listView.js其中包含ListView,我想展現給在index.android.js 我得到的錯誤是陣營本地導入一個類來顯示的ListView不工作

The development server returned response error code: 500 

URL: http://10.0.2.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false 

Body: 
{"from":"D:\\ReactNative\\first_app\\index.android.js","to":"./app/otherClass/listView","message":"Unable to resolve module `./app/otherClass/listView` from `D:\\ReactNative\\first_app\\index.android.js`: could not resolve `D:\\ReactNative\\first_app\\app\\otherClass\\listView' as a folder: it did not contain a package, nor an index file","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]} 
processBundleResult 
    BundleDownloader.java:172 
access$100 
    BundleDownloader.java:38 
execute 
    BundleDownloader.java:108 
emitChunk 
    MultipartStreamReader.java:69 
readAllParts 
    MultipartStreamReader.java:116 
onResponse 
    BundleDownloader.java:96 
execute 
    RealCall.java:135 
run 
    NamedRunnable.java:32 
runWorker 
    ThreadPoolExecutor.java:1113 
run 
    ThreadPoolExecutor.java:588 
run 
    Thread.java:818 

index.android.js

import React, {Component} from 'react'; 
import {Text, View, AppRegistry, StyleSheet, TextInput,Switch} from 'react-native'; 
import listView from './app/otherClass/listView'; 
export default class first_app extends Component{ 
    constructor(){ 
    super(); 
    this.state={ 
     textValue:'Hello Mithun', 
     switchValue:false 
    } 
    } 
    switch_switch(value){ 
    this.setState({ 
    switchValue:value 
    }); 
    } 
    onTextChange(value){ 
    this.setState({ 
    textValue:value 
    }); 

    } 
    render(){ 
    return(
     <View> 
     <TextInput 
       placeholder="Enter some text" 
      value={this.state.textValue} 
      onChangeText={(value)=>this.onTextChange(value)} 
      /> 
      <Text>{this.state.textValue}</Text> 
      <Switch 
      value={this.state.switchValue} 
      onValueChange={(value)=> this.switch_switch(value)} 
      /> 

      <View> 
      <Text>{listView}</Text> 

      </View> 

     </View> 

    ); 
    } 
} 
const style=StyleSheet.create({ 
    myView: { 
     backgroundColor:'#00f' 
    }, 
    myText: { 
     color: '#fff' 
    } 
}); 
AppRegistry.registerComponent('first_app',()=>first_app); 

而且我listView.js

import React, {Component} from 'react'; 
import {Text, View, AppRegistry, StyleSheet, TextInput,ListView} from 'react-native'; 
const users=[ 
    {name:'Chiranjibi poudel'}, 
    {name:'Rishi ram mukhiya'}, 
    {name:'Mahendra Bhat'}, 
    {name:'Surya Man Shrestha'} 
] 
export default class listView extends Component{ 
    constructor(){ 
    super(); 
     const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2}); 
     this.state={ 
     userData: ds.cloneWithRows(users), 
     }; 
    } 
    renderRow(users,sectionId,rowId,highlightRow){ 
    return(
     <View> 
     <Text>{users.name}</Text> 
     </View> 
    ); 

    } 
    render(){ 
    return(
     <ListView 
     dataSource:{this.state.userData} 
     renderRow={(users) => <Text>{users}</Text>} 
     /> 

    ); 
    } 
} 
AppRegistry.registerComponent('listView',()=>listView); 

通往listView.js的路徑是絕對正確的。 我不知道我在哪裏錯了。 謝謝。

回答

1

我剛剛找到了答案。 1.確保你有正確的語法爲您import語句 2.嘗試運行一個或所有這些命令: - 清除守望手錶:watchman watch-del-all
- 刪除node_modules文件夾:rm -rf node_modules && npm install - 復位打包緩存:rm -fr $TMPDIR/react-*npm start -- --reset-cache。 第三個爲我工作。希望這個幫助。