ID不能得到解决或没有从javacodegeeks教程
问题描述:
我下面从http://www.javacodegeeks.com/2010/10/android-full-app-part-1-main-activity.htmlID不能得到解决或没有从javacodegeeks教程
一个Android应用程序教程中,我想我所做的几乎每件事场,但我仍然得到错误说“ID不能得到解决或者不是“试图引用main.xml 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将不会生成,并导致您描述的错误。 – WarrenFaith
你可以发布你的日志猫吗? –
[2013-07-08 18:43:08 - AndroidMovieSearchAppProject] W/ResourceType(688):错误的XML区块:标题大小172或总大小11144288大于数据大小0 [2013-07-08 18:43: 08 - AndroidMovieSearchAppProject] C:\ Users \ Workspace \ Android \ AndroidMovieSearchAppProject \ res \ menu \ movie_search_app.xml:3:错误:错误:找不到与给定名称相匹配的资源('title'为'@ string/action_settings' )。 –