Android Studio: Error in Layout Files - Header exp

2019-08-09 10:02发布

问题:

Every time I create a TextView and set a text to it, the AS-Editor would throw an error: "Header expected - Manifest file doesn't end with a final newline"

The code:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="eu.myurl.myproject"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="eu.myurl.myproject.MainActivity"
            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>

The error is already there when creating a new project. Hardcoded Strings also dont work.

Why is this happening and what can be done about?

Im using Android Studio 0.2.7 with JRE: 1.7.0_21

回答1:

Click on the word with the red line (that causes the mentioned error) Click Alt+Enter and choose

Un-inject Language/Reference

That's it! At least this worked for me on the same error