图像不存在错误

时间:2017-04-08 13:02:11

标签: react-native

我从React Native官方教程中引用了<Image source={require('./img/favicon.png')} />

图像代码就像 {"from":"F:\\ReactNativeProject\\FirstProject\\index.android.js","to":"./img/favicon.png","message":"Unable to resolve module `./img/favicon.png` from `F:\\ReactNativeProject\\FirstProject\\index.android.js`: Directory F:\\ReactNativeProject\\FirstProject\\img\\favicon.png doesn't exist","name":"UnableToResolveError","type":"UnableToResolveError","errors":[{}]}

当我尝试构建它时显示

开发服务器返回响应错误代码:500 网址:http://10.0.2.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false 体:

F:\ReactNativeProject\FirstProject\img

我将图片设置为favicon

的文件夹

,图片名称为F:/ReactNativeProject/FirstProject/index.android.js: Unexpected token (9:25) at F:\ReactNativeProject\FirstProject\index.android.js:9:25

为什么会显示错误?有人可以告诉我为什么?谢谢你的推荐。

新错误为import React, { Component } from 'react'; import{ AppRegistry, ScrollView, Image, Text, View } from 'react-native' class IScrolledDownAndWhatHappenedNextShockedMe extends Component { render() { return( <ScrollView> <Image source={../../img/favicon.png} /> </ScrollView> ); } } AppRegistry.registerComponent('FirstProject', () => IScrolledDownAndWhatHappenedNextShockedMe);

我的代码是

public HttpResponse<JsonNode> sendRequest(Map params) throws UnirestException {
        return Unirest.get(apiUrl).queryString("key", apiKey).queryString(params).asJson();
    }

1 个答案:

答案 0 :(得分:2)

require用于引用模块/文件。因此,您收到错误。

<Image source={require('./img/favicon.png')} />

应该是:

<Image source={path/favicon.png} />//path=path of image