简体   繁体   English

音频无法在android中播放。 android.content.res.Resources $ NotFoundException:资源ID#0x0

[英]Audio not playing in android. android.content.res.Resources$NotFoundException: Resource ID #0x0

I am trying to play an audio file in Android but it seems to crash and give a the ResourcesNotFoundException . 我正在尝试在Android中播放音频文件,但似乎崩溃了,并给出了ResourcesNotFoundException The audio file is saved in the raw folder inside res. 音频文件保存在res内的原始文件夹中。 The name of the audio file is determined by a randomly generated number which is then concatenated to "audio". 音频文件的名称由随机生成的数字确定,然后将其连接为“音频”。

int res = getResources().getIdentifier ( "audio"+arrayIndex, "raw","com.din.askak" );
MediaPlayer mPlayer = MediaPlayer.create ( MainActivity.this, res );

In the logcat it seems to throw the exception on the line creating the mediaPlayer. 在logcat中,似乎在创建mediaPlayer的行上抛出了异常。 I don't know what I seem to be doing wrong??? 我不知道我在做什么错???

Use of getIdentifier() function is discouraged. 不鼓励使用getIdentifier()函数。 It is much more efficient to retrieve resources by identifier rather than by name. 通过标识符而不是通过名称检索资源要高效得多。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android.content.res.Resources $ NotFoundException:资源ID#0x0 - android.content.res.Resources$NotFoundException: Resource ID #0x0 android.content.res.Resources $ NotFoundException:资源ID#0x0 - android.content.res.Resources$NotFoundException: Resource ID #0x0 Android:android.content.res.Resources$NotFoundException: 资源 ID #0x0 in - Android:android.content.res.Resources$NotFoundException: Resource ID #0x0 in android.content.res.Resources $ NotFoundException:资源ID#0x0 Android错误 - android.content.res.Resources$NotFoundException: Resource ID #0x0 Android error Android - android.content.res.Resources $ NotFoundException:资源ID#0x0 - Android - android.content.res.Resources$NotFoundException: Resource ID #0x0 GridView.FATAL例外:main android.content.res.Resources $ NotFoundException:字符串资源ID#0x0 - GridView.FATAL EXCEPTION: main android.content.res.Resources$NotFoundException: String resource ID #0x0 android.content.res.Resources$NotFoundException:使用 RecyclerView 时出现资源 ID #0x0 异常 - android.content.res.Resources$NotFoundException: Resource ID #0x0 exception while using RecyclerView android.content.res.Resources $ NotFoundException:onCreate()之后的资源ID#0x0 - android.content.res.Resources$NotFoundException: Resource ID #0x0 after onCreate() android.content.res.Resources $ NotFoundException:访问getResource()时的字符串数组资源ID#0x0 - android.content.res.Resources$NotFoundException: String array resource ID #0x0 while accessing getResource() android.content.res.Resources$NotFoundException: 字符串资源 ID #0x0 - android.content.res.Resources$NotFoundException: String resource ID #0x0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM