我是Android开发者的新手。我有一个非常简单的布局简单的“学习”应用程序。布局显示只有一个警告(硬编码字符串...应该使用@string资源),我怀疑是与问题有关。然而,在我的活动代码中,我有错误“R无法解析为变量”。android R无法解析,但布局没有错误
这里是在Java:
package com.example.treefields;
import android.app.Activity;
import android.os.Bundle;
public class TreeFieldsActivity extends Activity
{
public void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContextView (R.layout.activity_tree_fields);
}
}
而且,这里的布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<EditText
android:id="@+id/editText1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textMultiLine"
android:text="multiline text" />
</LinearLayout>
任何想法?谢谢。
清理并重建您的项目。如果仍未生成R,则报告错误。 – Shark 2012-07-30 20:51:12
错误可能出现在任何XML文件中,而不仅仅是您的布局。打开Eclipse的**包资源管理器**窗口,然后按照错误图标到任何地方出现错误或使用**问题**窗口。 – Sam 2012-07-30 20:52:19
也尝试删除R.java文件。它会重新构建,然后应该是正确的。 – edwoollard 2012-07-30 20:53:58