raw cannot be resolved or is not a field

前端 未结 3 441
小鲜肉
小鲜肉 2021-01-13 04:11

I\'m building an MP3 player into my app and I\'m getting an error stating \"raw cannot be resolved or is not a field\" on the line: mMediaPlayer = MediaPlayer.create(this, R

相关标签:
3条回答
  • 2021-01-13 04:57

    I'm not sure exactly what R.raw.test_cbr is (I did not write this code) can someone explain what R.raw.test_cbr is as well as how this can be resolved?

    R.raw refers to the "raw" resources placed in res/raw. "Raw" means that the resource file is included in the application package as-is, without any compile-time modifications.

    (In theory at least. I've had problems where the toolchain modified my raw resources but that's beyond the scope of this question.)

    You get this compile time error because you don't have the res/raw folder and the R.raw nested class is not generated in R.java.

    R.raw.test_cbr refers to a file test_cbr.ext in the res/raw folder, where ext is just some file extension.

    Since you're feeding MediaPlayer, you should place some audio media file test_cbr e.g. text_cbr.mp3 in res/raw and rebuild your application.

    0 讨论(0)
  • 2021-01-13 05:01

    The raw folder goes inside res folder of your Android Project. Onces inside /res, you cand find it through R.raw

    0 讨论(0)
  • 2021-01-13 05:03

    When I faced the issue, there was another issue. The name of the resource should contain only lowercase letters. If not, any reference to R causes an issue. Also extension is compulsory

    0 讨论(0)
提交回复
热议问题