React-native:端口相关错误

时间:2016-08-23 22:47:47

标签: react-native-android

我试图在模拟器上运行应用程序,我看到了这个错误 -

enter image description here

我确实在另一个终端运行了命令react-native start,并且打包器在8081上启动并运行。

知道问题可能是什么?

谢谢

2 个答案:

答案 0 :(得分:0)

必须存在语法错误,您可能正在定义名为' name'两次。试着检查一下。

答案 1 :(得分:0)

这是index.android.js



/* @flow */

/**
 * Android index
 */
'use strict';

var React = require('react-native');
var {
  AppRegistry,
} = React;

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 */

var MobileApp = require('./components/Index');

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




这就是index.js的样子



/* @flow */

/**
 * Index with route mapper
 */
'use strict';

var React = require('react-native');
var {
  View,
  AppRegistry,
  Navigator,
  AsyncStorage,
} = React;

var settings = require('../config/settings'),
  apiErrors = require('../stores/ApiErrors.json'),
  Util = require('../utils/Util');

//Components
var Accounts = require('./Accounts'),
  ActivityDashboard = require('./ActivityDashboard'),
  Advice = require('./Advice'),
  Dashboard = require('./Dashboard'),
  History = require('./History'),
  HealthQuiz = require('./HealthQuiz'),
  HealthQuizCover = require('./HealthQuizCover'),
  HealthQuizResult = require('./HealthQuizResult'),
  HumanAPIConnect = require('./HumanAPIConnect'),
  HumanConnectCordovaTest = require('./HumanConnectCordovaTest'),
  LogIn = require('./LogIn'),
  ManualAdd = require('./ManualAdd'),
  MedicalInfo = require('./MedicalInfo'),
  Overview = require('./Overview'),
  Records = require('./Records'),
  SignUp = require('./SignUp'),
  WelcomeScenes = require('./WelcomeScenes');

if (settings.mode === 'dev') {

}

var RouteMapper = function(route, navigator) {
  //Log route name
  console.log('Route: ' + route.name);

  if (route.name === 'Accounts') {
    return (
      <Accounts navigator={navigator} />
    );
  }
  else if (route.name === 'ActivityDashboard') {
    return (
      <ActivityDashboard navigator={navigator} />
    );
  } else if (route.name === 'Advice') {
    return (
      <Advice navigator={navigator}
        component={route.component}
      />
    )
  } else if (route.name === 'Dashboard') {
    return (
      <Dashboard navigator={navigator}
        component={route.component}
      />
    )
  } else if (route.name === 'HealthQuiz') {
    return (
      <HealthQuiz navigator={navigator} />
    );
  } else if (route.name === 'HealthQuizCover') {
    return (
      <HealthQuizCover navigator={navigator} />
    );
  } else if (route.name === 'HealthQuizResult') {
    return (
      <HealthQuizResult navigator={navigator}
        result={route.result}
      />
    );
  } else if (route.name === 'History') {
    return (
      <History navigator={navigator}
        component={route.component}
        metric={route.metric}
      />
    )
  } else if (route.name === 'HumanAPIConnect') {
    return (
      <HumanAPIConnect navigator={navigator} />
    );
  } else if (route.name === 'HumanConnectCordovaTest') {
    return (
      <HumanConnectCordovaTest navigator={navigator} />
    );
  } else if(route.name === 'LogIn') {
    return (
      <LogIn navigator={navigator} />
    );
  }  else if (route.name === 'LogOut') {
    AsyncStorage.multiRemove(['email', 'username', 'auth', 'gender', 'age']);
    console.log('Route: LogIn');

    return (
      <LogIn navigator={navigator} />
    );
  } else if(route.name === 'ManualAdd') {
    return (
      <ManualAdd navigator={navigator} />
    );
  } else if (route.name === 'MedicalInfo') {
    return (
      <MedicalInfo navigator={navigator} />
    );
  } else if (route.name === 'Overview') {
    return (
      <Overview navigator={navigator}
        mainSelection={true}
      />
    );
  } else if (route.name === 'Records') {
    return (
      <Records navigator={navigator}
        component={route.component}
        collection={route.collection}
      />
    );
  } else if (route.name === 'SignUp') {
    return (
      <SignUp navigator={navigator} />
    );
  } else if (route.name === 'WelcomeScenes') {
    return (
      <WelcomeScenes navigator={navigator}/>
    );
  }
};

var Index = React.createClass({

  getInitialState: function() {
    return {};
  },

  componentWillMount: function() {
    AsyncStorage.multiGet(['username', 'auth', 'gender', 'age']).then((values) => {
      var username = values[0][1],
        auth = values[1][1],
        gender = values[2][1],
        age = values[3][1],
        urlPattern = '/auth/confirm-auth/';

      if (!(username && auth && gender && age)) {
        console.log('No username and/or auth were found');
        this.setState({initialRoute: 'LogIn'});
      } else {
        this.setState({'username': username, 'auth': auth});
        Util.fetchAPIData(null, username, auth, urlPattern, null, this._handleAPIResponse,
          this._onMissingConnection, this._handleFetchError, false);
      }
    }).done();
  },

  _onMissingConnection: function() {
    this.setState({initialRoute: 'LogIn'});
  },

  _handleFetchError: function(error) {
    console.log(error);
    this.setState({initialRoute: 'LogIn'});
  },

  _handleAPIResponse: function(responseData) {
    //Set initial route depending on whether or not credentials are valid
    var initialRoute = (responseData.error == apiErrors.noError) ? 'Overview' : 'LogIn';
    this.setState({initialRoute: initialRoute});
  },

  render: function() {

    //For debugging purposes
    if (settings.mode === 'dev') {
      return (
        <Navigator
          initialRoute={{
            name: 'Accounts'
          }}
          renderScene={RouteMapper}
        />
      );
    }

    if (!('initialRoute' in this.state)) {
      return <View/>;
    }

    return (
      <Navigator
        initialRoute={{
          name: this.state.initialRoute
        }}
        renderScene={RouteMapper}
      />
    );
  },

});


module.exports = Index;
&#13;
&#13;
&#13;