【发布时间】:2014-07-07 01:39:32
【问题描述】:
所以我现在在我的程序中唯一的布局就是这个 activity_main 文件。我有一个 MainActivity 类。保存 xml 文件时出现构建错误,并且没有生成我的 R 文件。我读到的 R 文件未生成与 xml 错误有关。即使在构建时,我的 cml 中的 eclipse 也不会捕获这些错误。我已经包含了我的字符串 xml 文件、布局文件和 android 清单。非常感谢您的帮助,谢谢。
字符串 XML 文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">django mouse</string>
<string name="title_activity_main">MainActivity</string>
<string name="hello_world">Hello world!</string>
<string name="welcome_header">Welcome to Django</string>
<string name="start_instructions">To begin enter your local ip address and then click the start button</string>
<string name="pebb_accel_header">Pebble Accelerometer Data</string>
<string name="main_x_coordinate">X: </string>
<string name="main_y_coordinate">Y: </string>
<string name="main_z_coordinate">Z: </string>
<string name="up_button">up</string>
<string name="down_button">down</string>
<string name="left_button">left</string>
<string name="right_button">right</string>
<string name="click_button">click</string>
<string name="start_button">start</string>
</resources>
activity_main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="20dp"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/welcome_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:gravity="center_horizontal"
android:text="@string/welcome_header"
android:textColor="@color/Black"
android:textSize="22sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/start_stop_instructions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="75dp"
android:text="@string/start_instructions"
android:textColor="@color/Black"
android:textSize="18sp" />
<TextView
android:id="@+id/welcome_sub_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/start_stop_instructions"
android:paddingTop="16dp"
android:text="@string/pebb_accel_header"
android:textColor="@color/Black"
android:textSize="18sp" />
<LinearLayout
android:id="@+id/accel_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/pebb_accel_header"
android:orientation="vertical" >
<TextView
android:id="@+id/main_x_coordinate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/main_x_coordinate"
android:textColor="@color/Black" />
<TextView
android:id="@+id/main_y_coordinate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/main_y_coordinate"
android:textColor="@color/Black" />
<TextView
android:id="@+id/main_z_coordinate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/main_z_coordinate"
android:textColor="@color/Black" />
</LinearLayout>
<Button
android:id="@+id/up_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/accel_data"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:text="@string/up_button" />
<Button
android:id="@+id/down_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/up_button"
android:layout_centerHorizontal="true"
android:layout_marginTop="48dp"
android:text="@string/down_button" />
<Button
android:id="@+id/left_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/up_button"
android:layout_toLeftOf="@id/up_button"
android:text="@string/left_button" />
<Button
android:id="@+id/right_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/up_button"
android:layout_toRightOf="@id/up_button"
android:text="@string/right_button" />
<Button
android:id="@+id/click_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/up_button"
android:layout_toLeftOf="@id/right_button"
android:layout_toRightOf="@id/left_button"
android:text="@string/click_button" />
</RelativeLayout>
<Button
android:id="@+id/main_start_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="@string/start_button"
</RelativeLayout>`
Android 清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.housedroid.djangomouse"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.housedroid.djangomouse.MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
【问题讨论】:
-
您的最后一个按钮缺少关闭 /> 更正错误,清理并重建项目。我很惊讶 Eclipse 没有显示错误,activity_main 下应该有一个波浪状的红色下划线。