R.layout.main cannot be resolved.
来源:互联网 发布:晶体结构解析软件 编辑:程序博客网 时间:2024/06/13 15:44
这几天闲着没事就下了个android的SDK来玩玩,下面是我在用eclipse进行android开发环境搭建时遇到的问题
解决方案:
(1) 删除第3行的 "import android.R;".
(2) 勾选上Eclipse中的"Project->Build Automatically";
原因分析:
(1) 删除"import android.R"之后工程就是从/res文件夹下自动生成的资源文件里去解析了,否则它会从Android的资源类里去找。
(2) 但为什么勾选上动态构建"Build Automatically",我不是太清楚。刚接触Eclipse,稍后可能会更明白些。
关于Eclipse的动态构建
使用Eclipse进行Java开发,您首先注意到的就是它的编译是多么智能。进入Preferences(WindowMenu > Preferences)并启用动态构建(Workbench > Build Automatically)。现在,每当您保存文件时,Eclipse将会自动编译该文件以及依赖于该文件的文件。因此,当您想运行您的应用程序时,它基本上已经保存好并且是最新版本。当您处理大型代码基时,这可以节约不少时间。如果您不得不使用其他IDE,那么您首先失去的就是该特性的简单性。
当您使用Eclipse时,您将会一次又一次地感受到这样一个底层原理:IDE了解代码。Eclipse不仅仅是一个能在以文件为中心的基础上处理代码和其他事情的编译器,它还能够查看源代码并聪明地加以处理。它的智能编译能力通过它能够明白表达在导入语句中的依赖性而得到了证明。
问题:
下面代码中的第12行出错:R.layout.main cannot be resolved.
下面代码中的第12行出错:R.layout.main cannot be resolved.
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> 1 package com.Tealc.DaysBetween;
2
3 import android.R;
4 import android.app.Activity;
5 import android.os.Bundle;
6
7 public class DaysBetween extends Activity {
8 /** Called when the activity is first created. */
9 @Override
10 public void onCreate(Bundle savedInstanceState) {
11 super.onCreate(savedInstanceState);
12 setContentView(R.layout.main);
13 }
14 }
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> 1 package com.Tealc.DaysBetween;
2
3 import android.R;
4 import android.app.Activity;
5 import android.os.Bundle;
6
7 public class DaysBetween extends Activity {
8 /** Called when the activity is first created. */
9 @Override
10 public void onCreate(Bundle savedInstanceState) {
11 super.onCreate(savedInstanceState);
12 setContentView(R.layout.main);
13 }
14 }
解决方案:
(1) 删除第3行的 "import android.R;".
(2) 勾选上Eclipse中的"Project->Build Automatically";
原因分析:
(1) 删除"import android.R"之后工程就是从/res文件夹下自动生成的资源文件里去解析了,否则它会从Android的资源类里去找。
(2) 但为什么勾选上动态构建"Build Automatically",我不是太清楚。刚接触Eclipse,稍后可能会更明白些。
关于Eclipse的动态构建
使用Eclipse进行Java开发,您首先注意到的就是它的编译是多么智能。进入Preferences(WindowMenu > Preferences)并启用动态构建(Workbench > Build Automatically)。现在,每当您保存文件时,Eclipse将会自动编译该文件以及依赖于该文件的文件。因此,当您想运行您的应用程序时,它基本上已经保存好并且是最新版本。当您处理大型代码基时,这可以节约不少时间。如果您不得不使用其他IDE,那么您首先失去的就是该特性的简单性。
当您使用Eclipse时,您将会一次又一次地感受到这样一个底层原理:IDE了解代码。Eclipse不仅仅是一个能在以文件为中心的基础上处理代码和其他事情的编译器,它还能够查看源代码并聪明地加以处理。它的智能编译能力通过它能够明白表达在导入语句中的依赖性而得到了证明。
2010/3/8 更新:在最新的SDK2.1的新建工程里已经不存在import.android.R,解决方法是将鼠标放到R上,Eclipse会提示你一些fix,如下图所示。选择第二项可fix.
- R.layout.main cannot be resolved解决办法
- R.layout.main cannot be resolved.
- Android R.Layout.Main cannot be resolved
- Troubleshoot: R.Layout.Main cannot be resolved
- R.Layout.Main cannot be resolved (转载)
- R.layout.main cannot be resolved
- R.layout.main cannot be resolved解决办法
- R.layout.main cannot be resolved 问题 补充回答。
- Android编程报错:R.layout.main cannot be resolved
- Android Error:main cannot be resolved or is not a field,异常语句:setContentView(R.layout.main);
- R.layout.main connot be resolved 和R.java消失问题
- Android: R cannot be resolved
- R.layout.xxx cannot be resolved or is not a field问题解决办法
- eclipse 找不到layout文件,出现错误-R cannot be resolved解决办法
- R cannot be resolved错误产生分析
- R cannot be resolved - Android error
- R.string.* cannot be resolved 错误
- R cannot be resolved 的解决办法
- 程序员何去何从?
- 百花齐放
- AOP设计模式的总结
- 赫耳墨斯与地神
- 最大子序列和问题
- R.layout.main cannot be resolved.
- 如何降低软件行业中新员工离职率
- Android EditText 光标颜色的修改方法
- 看看那个浮华外衣, 谁是Steve、谁是Dennis
- FP算法
- Android 显示系统 --- Surface Flinger
- java中判断字符串是否为数字的三种方法
- MYSQL导入导出.sql文件
- c++中虚继承机制 内存布局