“Tag <Activity > attribute name has invalid character ' '. ” Android Manifest

自闭症网瘾萝莉.ら 提交于 2020-01-02 04:27:27

问题


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:

<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:

        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++;
    }

回答1:


android:name is supposed to have reference of your class path which represents the activity. It must not contain any special characters or spaces.

For example:

android:name="com.json.test.MainActivity"

Here, MainActivity is the class file which extends an Activity.




回答2:


Your name attribute should contain your activity class:

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")




回答3:


android:name can't contain white spaces, it's the name of a class.




回答4:


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.

Secondly, if you actually aren't missing 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.




回答5:


your android:name does not contain white spaces or special characters. for example android name should be like this

<activity  
android:name="com.example.users.projectname.MainActivity">
</activity>



回答6:


In additional package is also needed to be named in English alphabet other case AndroidManifest gives similar error. That I experienced



来源:https://stackoverflow.com/questions/22333173/tag-activity-attribute-name-has-invalid-character-android-manifest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!