(1)检查Project->Build Automatically是否打上勾,打上勾后Project->Clean... ,重新编译。
(2)还有一种情况就是xml布局文件出错,导致不能编译通过。
(3)重命名gen目录下的包名,就会出现这个错误,不知道为什么?
(4)当写完语句setContentView(R.layout.main);会提示import,有下面两个选项:
import android.R;
import com.example.androidlearning.R;
选第一个则会报错main cannot be resolved or is not a field,选第二个就好了。