R 1不能被解析到一个变量 - 的Hello World [英] R cannot be resolved to a variable - Hello World
问题描述
我知道很多人有过这样的问题,我已搜查谷歌/堆栈溢出,但我有点仍然无法弄清我做错了。
包的HelloWorld;
进口android.app.Activity;
进口android.os.Bundle;
进口android.widget.TextView;
公共类HelloWorldActivity延伸活动{
/ **第一次创建活动时调用。 * /
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
// TextView的电视=新的TextView(本);
//字符串Hello =的Hello World!;
// tv.setText(你好);
//的setContentView(TV);
}
}
我试图寻找不必要的进口android.R;
语句,以及建筑/清洁/清爽/等等,但我似乎无法弄清楚。也许这是与我安装我的软件开发工具包的方式有问题?我不觉得有什么,但我很新的这所以很可能我的地方做了一个大错。
另外,我收到此错误:
[2011-12-13 18点18分46秒 - com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper]分析器例外,C:\用户\ MYNAME \ Android的开发\的Hello World \的Hello World \的AndroidManifest.xml:处理指令目标匹配[XX] [MM] [11]不允许
谁能帮助我?谢谢!
编辑:我的XML文件:
< XML版本=1.0编码=UTF-8&GT?;
<舱单的xmlns:机器人=http://schemas.android.com/apk/res/android
包=的HelloWorld Mylove
安卓版code =1
机器人:VERSIONNAME =1.0>
<使用-SDK安卓的minSdkVersion =10/>
<应用
机器人:图标=@可绘制/ ic_launcher
机器人:标签=@字符串/ APP_NAME>
<活动
机器人:名称=。HelloWorldActivity
机器人:标签=@字符串/ APP_NAME>
<意向滤光器>
<作用机器人:名称=android.intent.action.MAIN/>
<类机器人:名称=android.intent.category.LAUNCHER/>
&所述; /意图滤光器>
< /活性GT;
< /用途>
< /舱单>
请参阅此行您的清单的(在开放的<舱单/>
标签)的
包=的HelloWorld Mylove
这不是有效的软件包名称,必须改变。通常一个包名由小写的话,用点分隔出来,例如:
com.hello.world
请参阅命名一个包。更改为一个有效的名称。
由于这是总的一些工作,因为你必须在不同的places¹改变它的(有时失败,我出于某种原因)的,我建议刚通过创建一个新项目在Eclipse中新的Android项目向导。这会问你包的名称在步骤4。请一定要按照上面提到的命名约定。您应该结束了pretty的大同小异code。另外,您可以尝试在项目资源管理器在你的项目上单击右键,选择 Android的工具 - >重命名应用程序包
。
¹的显现出来,你的* .java文件都存储在文件夹中,源文件中的包
语句的
I know many people have had this problem and I have searched Google/Stack Overflow, but I somehow still can't figure out what I'm doing wrong.
package HelloWorld;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// TextView tv = new TextView(this);
// String hello = "Hello World!";
// tv.setText(hello);
// setContentView(tv);
}
}
I tried searching for unnecessary import android.R;
statements, as well as building/cleaning/refreshing/etc, but I just can't seem to figure it out. Maybe it's a problem with the way I've installed my SDKs? I don't think there is, but I'm very new to this so it's likely I made a blunder somewhere.
Also, I am getting this error:
[2011-12-13 18:18:46 - com.android.ide.eclipse.adt.internal.project.AndroidManifestHelper] Parser exception for C:\Users\MYNAME\Android Development\Hello World\Hello World\AndroidManifest.xml: The processing instruction target matching "[xX][mM][lL]" is not allowed.
Can anyone help me? Thanks!
EDIT: My XML file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="HelloWorld Mylove"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".HelloWorldActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
See this line in your manifest (at the opening of the <manifest />
tag)
package="HelloWorld Mylove"
That's not a valid package name and has to change. Usually a package name consists out of lowercase words, seperated by dots, e.g.:
com.hello.world
See Naming a Package. Change this to a valid name.
Since this is overall a bit of work, because you have to change it in various places¹ (and sometimes failed for me for some reason), I'd recommend just creating a new project via the new android project wizard in eclipse. This will ask you for a package name in step 4. Make sure to follow the naming conventions mentioned above. You should end up with pretty much the same code. Alternatively you can try to right-click on your project in the project explorer and select Android Tools -> Rename Application Package
.
¹ The manifest itself, the folders where your *.java files are stored, the package
statement within the source files
这篇关于R 1不能被解析到一个变量 - 的Hello World的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!