Id无法解析或不是javacodegeeks教程中的字段

Id无法解析或不是javacodegeeks教程中的字段,java,android,Java,Android,我正在学习一个android应用程序教程 我认为我做的几乎每件事都是对的,但在试图引用main.xml id的代码中仍然出现错误,即“id无法解析或不是字段”。 以下是我的MovieSearchAppActivity.java代码 public class MovieSearchAppActivity extends Activity implements OnClickListener { private static final String EMPTY_STRING= ""; priva

我正在学习一个android应用程序教程

我认为我做的几乎每件事都是对的,但在试图引用main.xml id的代码中仍然出现错误,即“id无法解析或不是字段”。 以下是我的MovieSearchAppActivity.java代码

public class MovieSearchAppActivity extends Activity implements OnClickListener {

private static final String EMPTY_STRING= "";
private EditText searchEditText;
private RadioButton movieSearchRadioButton;
private RadioButton peopleSearchRadioButton;
private RadioGroup searchRadioGroup;
private TextView searchTypeTextView;
private Button searchButton;


            @Override
            protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    this.findAllViewsById();

    movieSearchRadioButton.setOnClickListener(radioButtonListener);
    peopleSearchRadioButton.setOnClickListener(radioButtonListener);
    searchButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
        String query = searchEditText.getText().toString();
        if (movieSearchRadioButton.isChecked()){
            longToast(movieSearchRadioButton.getText() + " " + query);      
        }
        else if(peopleSearchRadioButton.isChecked()){
            longToast(peopleSearchRadioButton.getText() + " " + query);
        }
        }
    });
    searchEditText.setOnFocusChangeListener(new DftTextOnFocusListener(getString(R.string.search))); //error:"search cannot be resolved or in field.
    int id = searchRadioGroup.getCheckedRadioButtonId();
    RadioButton radioButton = (RadioButton) findViewById(id);
    searchTypeTextView.setText(radioButton.getText());

}
private void findAllViewsById() {
    EditText searchEditText = (EditText) findViewById(R.id.search_edit_text); //search_edit_text cannot be resolved or is not in field. same for below reference.
    movieSearchRadioButton = (RadioButton) findViewById(R.id.movie_search_radio_button);
    peopleSearchRadioButton = (RadioButton) findViewById(R.id.people_search_radio_button);
    searchRadioGroup = (RadioGroup) findViewById(R.id.search_radio_group);
    searchTypeTextView = (TextView) findViewById(R.id.search_type_text_view);
    searchButton = (Button) findViewById(R.id.search_button);
    }
这是我的main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
    android:id="@+id/search_edit_text"
    android:text="@string/search"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
 />
<RadioGroup
    android:id="@+id/search_radio_group"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    <RadioButton
        android:id="@+id/movie_search_radio_button"
        android:checked="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/movies" />
    <RadioButton
        android:id="@+id/people_search_radio_button"
        android:checked="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/people" />
</RadioGroup>

<TextView 
    android:id="@+id/search_type_text_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#ffffff" />
<Button
    android:id="@+id/search_button"
    android:text="@string/search"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />


</LinearLayout>

这是我的strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="hello_World">Search!</string>
<string name="app_name">MovieSearchApp</string>
<string name="search">Search</string>
<string name="movies">Movies</string>
<string name="people">People</string>

</resources>

搜索!
电影搜索
搜寻
影视
人

尝试清理项目并重建。从Eclipse菜单“项目”->“清理…”。

您的xml文件是否报告问题?如果是这样,将不会生成R,这将导致您描述的错误。您可以发布您的日志目录吗?[2013-07-08 18:43:08-AndroidMoviesearchapproject]W/ResourceType(688):错误的XML块:标题大小172或总大小11144288大于数据大小0[2013-07-08 18:43:08-AndroidMoviesearchapproject]C:\Users\Workspace\Android\androidmoviesearchapproject\res\menu\movie\u search\u app.xml:3:错误:错误:找不到与给定名称匹配的资源(在'title'处,值为'@string/action\u settings')。不,我的xml没有报告任何问题。是否重新生成了R.java?我不知道,它建议导入R.java来修复这个bug。我认为您应该检查一下R.java是否被重新生成。否则,您的Android开发环境可能会有问题。