最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Android代码R.layout.main出错:R cannot be resolved to a variable

Android crifan 6883浏览

【问题】

参考别人的代码:

Directory Browser Application

其中遇到了:

R.layout.main

会出错:

R cannot be resolved to a variable

【解决过程】

1.后来经过自己瞎折腾,大概搞懂了R的含义:

R,大概相当于,当前Runtime的变量 ->

2. 对应的R下面,有很多个东西,包括Layout:

R runtime include many

 

【总结】

而对应的解决此错误的方法是,参考其提示,去导入对应的系统的R:

import android.R;

或当前的项目的R:

import crifan.com.downloadsongtastemusic.R;

 

关于这两个R的区别,详见:

【已解决】Android中关于代码R.layout.main出错:main cannot be revolved or is not a field

转载请注明:在路上 » 【已解决】Android代码R.layout.main出错:R cannot be resolved to a variable

87 queries in 0.228 seconds, using 19.14MB memory