Java “标记 <Activity> 属性名称包含无效字符 ' '。” Android 清单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22333173/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Tag <Activity > attribute name has invalid character ' '. " Android Manifest
提问by SoulSlayerAbad
I am getting the error "Tag attribute name has invalid character ' '. " in the Android Manifest, while there is no obviously invalid character. Here is the code:
我在 Android Manifest 中收到错误“Tag attribute name has invalid character ' '.”,但没有明显无效的字符。这是代码:
<activity
android:name="Quiz 31"
android:configChanges="orientation|keyboardHidden"
android:label="Quiz 31"
android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="com.SoulSlayerAbad.AMQ.QUIZ31" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
As you can see, no ' ' character in the code. Does anyone know why this is happening? One thing to note is that I generated this piece of code using a few lines of Java run inside of Eclipse console. The code for that is:
如您所见,代码中没有 ' ' 字符。有谁知道为什么会这样?需要注意的一件事是,我使用 Eclipse 控制台内运行的几行 Java 生成了这段代码。代码是:
int Begin = 0, End = 0;
Scanner sc = new Scanner(System.in);
String Text = " <activity "+
"android:name=\"Quiz "+Begin+"\" "+
"android:configChanges=\"orientation|keyboardHidden\" "+
"android:label=\"Quiz "+Begin+"\" "+
"android:screenOrientation=\"portrait\" "+
"android:theme=\"@android:style/Theme.NoTitleBar\" > "+
"<intent-filter> "+
"<action android:name=\"com.SoulSlayerAbad.AMQ.QUIZ"+Begin+"\" /> "+
"<category android:name=\"android.intent.category.DEFAULT\" /> "+
"</intent-filter> "+
"</activity> ";
System.out.println("Begining:");
Begin = sc.nextInt();
System.out.println("End At:");
End = sc.nextInt();
while(Begin <= End){
System.out.println(Text);
Begin++;
}
采纳答案by waqaslam
android:name
is supposed to have reference of your class path which represents the activity. It must not contain any special characters or spaces.
android:name
应该有代表活动的类路径的参考。它不得包含任何特殊字符或空格。
For example:
例如:
android:name="com.json.test.MainActivity"
Here, MainActivity
is the class file which extends an Activity
.
在这里,MainActivity
是扩展一个Activity
.
回答by Jason C
Well for starters you're missing an escaped quote; are you sure that code compiles?
对于初学者来说,你错过了一个转义的报价;你确定代码可以编译吗?
"<action android:name=\"com.SoulSlayerAbad.AMQ.QUIZ"+Begin+"\" /> "+
Slash missing before the double quote just before +Begin
.
之前的双引号前缺少斜线+Begin
。
Secondly, if you actually aren'tmissing that slash, but when you pasted it here it made it look like it, perhaps an odd control character made it into that line.
其次,如果你实际上没有遗漏那个斜线,但是当你把它粘贴在这里时它看起来像它,也许是一个奇怪的控制字符使它进入了那一行。
Try deleting that line and retyping it from scratch.
尝试删除该行并从头开始重新键入。
You could also open your manifest file in a hex editor and verify that no strange non-printable characters are mixed in.
您还可以在十六进制编辑器中打开您的清单文件,并验证没有混入奇怪的不可打印字符。
回答by marcinj
Your name attribute should contain your activity class:
您的 name 属性应包含您的活动类:
android:name The name of the class that implements the activity, a subclass of Activity. The attribute value should be a fully qualified class name (such as, "com.example.project.ExtracurricularActivity")
android:name 实现Activity的类名,Activity的子类。属性值应该是完全限定的类名(例如,“com.example.project.ExtracurricularActivity”)
回答by Jon Ander Pe?alba
android:name
can't contain white spaces, it's the name of a class.
android:name
不能包含空格,它是一个类的名称。
回答by Vamsi Abbineni
your android:name
does not contain white spaces or special characters. for example android name should be like this
您的android:name
不包含空格或特殊字符。例如android名称应该是这样的
<activity
android:name="com.example.users.projectname.MainActivity">
</activity>
回答by Sam
In additional package
is also needed to be named in English alphabet other case AndroidManifest gives similar error. That I experienced
此外 package
还需要以英文字母命名其他情况 AndroidManifest 给出类似的错误。我所经历的