Java 如果我知道文件字符串名称,如何访问R.file?

Java 如果我知道文件字符串名称,如何访问R.file?,java,android,string,Java,Android,String,我正在制作一个程序,它需要用MediaPlayer.create(这个,R.raw.filename)打开各种歌曲但是因为我有很多歌曲,我需要用String s=“song”+Integer.toString(I)以编程方式记录文件名在我的for循环中。(文件名为song1、song2、song3等) 但问题是,当我尝试使用R.raw.s访问文件时,它会显示“未解析的符号s” 有什么帮助吗?int identifier=getResources().getIdentifier(s,“video/

我正在制作一个程序,它需要用
MediaPlayer.create(这个,R.raw.filename)打开各种歌曲
但是因为我有很多歌曲,我需要用
String s=“song”+Integer.toString(I)以编程方式记录文件名在我的for循环中。(文件名为song1、song2、song3等)

但问题是,当我尝试使用R.raw.s访问文件时,它会显示“未解析的符号s”


有什么帮助吗?

int identifier=getResources().getIdentifier(s,“video/mp3”,getPackageName());创建(此,标识符)