Android Head First美国宇航局日常图像应用程序

时间:2015-01-19 21:23:52

标签: android android-layout

我正在使用头部第一个教程,但也使用android studio。该计划不会运行;这是我的代码:

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

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

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

<TextView
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:id=”@+id/imageTitle”
    android:layout_width=”wrap_content”
    android:layout_height=”wrap_content”
    android:text=”@string/Title”/>

<TextView
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:id=”@+id/imageDate”
    android:layout_width=”wrap_content”
    android:layout_height=”wrap_content”
    android:text=”@string/Date”/>

<ImageView
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:id=”@+id/imageDisplay”
    android:layout_width=”wrap_content”
    android:layout_height=”wrap_content”
    android:src=”@drawable/test_image”/>

<TextView
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:id=”@+id/imageDescription”
    android:layout_width=”wrap_content”
    android:layout_height=”wrap_content”
    android:text=”@string/Description”/>

java代码:

package com.example.ker_david.nasadailyimage;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;


public class MyNasaDailyImage extends ActionBarActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_nasa_daily_image);
            }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.my_nasa_daily_image, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

错误:

  Information:Gradle tasks [:app:assembleDebug]
           :app:preBuild
          :app:compileDebugNdk UP-TO-DATE
          :app:preDebugBuild
          :app:checkDebugManifest
          :app:preReleaseBuild
          :app:prepareComAndroidSupportAppcompatV71910Library UP-TO-DATE
          :app:prepareDebugDependencies
           :app:compileDebugAidl UP-TO-DATE
          :app:compileDebugRenderscript UP-TO-DATE
          :app:generateDebugBuildConfig UP-TO-DATE
          :app:generateDebugAssets UP-TO-DATE
          :app:mergeDebugAssets UP-TO-DATE
          :app:generateDebugResValues UP-TO-DATE
          :app:generateDebugResources UP-TO-DATE
          :app:mergeDebugResources UP-TO-DATE
           :app:processDebugManifest UP-TO-DATE
           :app:processDebugResources
                    C:\Users\Ker-    David\AndroidStudioProjects\NasaDailyImage\app\src\main\res\layout\activity_my_nasa_daily_image.xml
    Error:(30) Error parsing XML: not well-formed (invalid token)
    Error:(30) Execution failed for task ':app:processDebugResources'.
    > com.android.ide.common.internal.LoggedErrorException: Failed to run command:
        C:\Program Files (x86)\Android\android-studio\sdk\build-tools\android-4.4W\aapt.exe package -f --no-crunch -I C:\Program Files (x86)\Android\android-studio\sdk\platforms\android-20\android.jar -M C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\intermediates\manifests\debug\AndroidManifest.xml -S C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\intermediates\res\debug -A C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\intermediates\assets\debug -m -J C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\generated\source\r\debug -F C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\intermediates\libs\app-debug.ap_ --debug-mode --custom-package com.example.ker_david.nasadailyimage -0 apk --output-text-symbols C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\intermediates\symbols\debug
    Error Code:
        1
    Output:
        C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\intermediates\res\debug\layout\activity_my_nasa_daily_image.xml:30: error: Error parsing XML: not well-   formed (invalid token)
           Information:BUILD FAILED
            Information:Total time: 6.768 secs
           Information:2 errors
           Information:0 warnings
          Information:See complete output in console`

The C:\Users\Ker-    David\AndroidStudioProjects\NasaDailyImage\app\src\main\res\layout\activity_my_nasa_daily_image.xml
Error:(30) Error parsing XML: not well-formed (invalid token)
Error:(30) Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\Program Files (x86)\Android\android-studio\sdk\build-tools\android-4.4W\aapt.exe package -f --no-crunch -I C:\Program Files (x86)\Android\android-studio\sdk\platforms\android-20\android.jar -M C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\intermediates\manifests\debug\AndroidManifest.xml -S C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\intermediates\res\debug -A C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\intermediates\assets\debug -m -J C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\generated\source\r\debug -F C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\intermediates\libs\app-debug.ap_ --debug-mode --custom-package com.example.ker_david.nasadailyimage -0 apk --output-text-symbols C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\intermediates\symbols\debug
Error Code:
    1
Output:
    C:\Users\Ker-David\AndroidStudioProjects\NasaDailyImage\app\build\intermediates\res\debug\layout\activity_my_nasa_daily_image.xml:30: error: Error parsing XML: not well-   formed (invalid token)
       Information:BUILD FAILED
        Information:Total time: 6.768 secs
       Information:2 errors
       Information:0 warnings
      Information:See complete output in console

所有android:id = @ + id / imageTitle给出了属性值预期错误

1 个答案:

答案 0 :(得分:0)

XML的主要问题是所有视图都有两个冗余属性。

    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:layout_width=”wrap_content”
    android:layout_height=”wrap_content”

应删除前两行。我还建议为不同的视图使用不同的ID。