【问题标题】:Can't load image in react-native无法在 react-native 中加载图像
【发布时间】:2021-10-05 06:49:37
【问题描述】:

我有点困惑,因为我只想在我的代码中插入一个图像,而我的 Android Studio 正在尝试查找索引文件。

这是我用来导入图像的代码:

return (
  <View>
    {/*Image*/}
    <Image
      style={styles.image}
      source={require("../../assets/images/motor_scooter.png")}
    />
  </View>
);

我收到以下错误:

Syntax Error
None of these file exist
*motor_scooter.png
*src\assets\images\motor_scooter.png\index(.native|.anroid.js|.native.js|.js|.android.json|.json|
.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)

我不明白为什么它需要索引。你能帮帮我吗?

谢谢

【问题讨论】:

  • 请确保您从正确的路径获取图像。
  • 你传递的图片路径错误motor_scooter.png../../assets/images/motor_scooter.png中不存在。
  • 你确定吗?这是我的目录的图片:ibb.co/x2547bg
  • 您能否展示您的整个设置以及从文件夹结构中的哪个位置调用代码?
  • 这里是整个结构,带有代码和错误消息的截图:ibb.co/qFpN6Ns

标签: react-native android-studio


【解决方案1】:

我发现了“下划线”造成的问题。我刚刚将它重命名为“motorscooter.png”,它工作了

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-17
    • 2016-05-17
    • 2017-07-21
    • 1970-01-01
    • 2019-03-22
    • 2016-11-02
    • 1970-01-01
    • 2017-06-04
    相关资源
    最近更新 更多