Android 编辑文本无法解析或不是字段

Android 编辑文本无法解析或不是字段,android,eclipse,Android,Eclipse,我在Eclipse的Android.com上做教程时点击了“Run”,得到了“edit_文本无法解析或不是字段”。这是我的MainActivity'代码 import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.R; public cla

我在Eclipse的Android.com上做教程时点击了“Run”,得到了“edit_文本无法解析或不是字段”。这是我的MainActivity'代码

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.R;

public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.Tutorial.MESSAGE";

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


/** Called when the user clicks the Send button */
public void sendMessage (View view){
    // Do something in response to button
    Intent intent=new Intent (this, DisplayMessageActivityNewNew.class);
    EditText editText = (EditText) findViewById(R.id.edit_text);
    String message = editText.getText().toString();
    intent.putExtra(EXTRA_MESSAGE, message);
    startActivity(intent);
}}
我的第二项活动是:

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
import android.widget.TextView;

public class DisplayMessageActivityNewNew extends Activity {
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    // Get the message from the intent
    Intent intent = getIntent();
    String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);

    // Create the text view
    TextView textView = new TextView(this);
    textView.setTextSize(40);
    textView.setText(message);

    // Set the text view as the activity layout
    setContentView(textView);
}

/**
 * Set up the {@link android.app.ActionBar}, if the API is available.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // This ID represents the Home or Up button. In the case of this
        // activity, the Up button is shown. Use NavUtils to allow users
        // to navigate up one level in the application structure. For
        // more details, see the Navigation pattern on Android Design:
        //
        // http://developer.android.com/design/patterns/navigation.html#up-vs-back
        //
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);

}
Main_Activity.xml

<LinearLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="horizontal"
tools:context="MainActivity" >
<EditText android:id="@+id/edit_message"
    android:layout_weight="1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:hint="@string/edit_message"/>
<Button android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_send" 
        android:onClick="sendMessage"/>
</LinearLayout>


不知道是什么问题,但如果您有任何帮助,我们将不胜感激。提前感谢。

删除下面的导入

import android.R;

删除@Raghunandan提到的导入,清理您的项目。检查UIXMLS某些组件在创建项目的资源文件时可能会干扰ide。
编辑:我看到您使用了android.R.id.home,这迫使您导入android.R,它只是将任何对R的引用作为对android.R的引用,无论您在哪里使用R,都只需使用您的packagename.R.Resourcename

这仍然是一个问题,但现在我有了“活动列表”项无法解析或不是字段。@coolbob5413进一步查看代码。除了我在第24行“维护活动”中提到的以外,我没有发现任何错误。好吧,我不知道怎么做,因为我是新手。请您解释一下好吗?@coolbob5413
导入您的packagename.R。此外,如果资源文件(即res文件夹下)中存在任何错误,请将其修复为“清理并构建”,只需清理项目,然后在使用PackageName.R.ideep初始化视图时替换任何R.id引用,因为这是项目的R(资源)文件。android.R是android包中的通用资源文件。教程是一个类吗??因为R不是tutorial的子类。最可能的例子是包。因此,请输入示例;com.example.R,或者只是example.R?好的,现在请填写我的答案,我正在同时阅读您在另一个答案中的注释。id是编辑消息或编辑文本。如果com.example.R无法解析,那就意味着您的ide不可用;t自行构建R文件。您需要重新检查已创建的所有用户界面xml文件。其中一个视图导致出现问题