2017-04-08 11 views
0

React Native公式チュートリアルのScrollViewの参照を受けました。 500 URL:http://10.0.2.2:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false 本体:画像が存在しないエラー

{"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":[{}]} 

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

のような画像コードに私はそれを構築しよう

が開発サーバーが応答エラーコードを返したことを示しています画像をフォルダに設定します。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); 

答えて

2

requireですが、モジュール/ファイルを参照するために使用されます。したがって、あなたはエラーを取得しています。あなたの応答のための

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

おかげで、私はそれを得ることはありません。

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

はする必要があります。私のルートが 'F:\ ReactNativeProject \ FirstProject \ img'であれば私の場合は' 'のようにしてください。それは最後に失敗する。 –

+0

try <画像ソース= {../../ img/favicon.png} />または<画像ソース= {../../../ img/favicon.png} /> – Ved

+0

ありがとうございました。それと一緒に変わるが、それは別のエラーを示す、私は反応ネイティブのbignnerだ、もう一度私を助けてくれますか?ありがとう。 –

関連する問題