Android 无法解析R.id。安卓
我有密码:Android 无法解析R.id。安卓,android,android-tabhost,android-xml,Android,Android Tabhost,Android Xml,我有密码: package com.finalyearproject.cookmefood; import android.app.Activity; import android.os.Bundle; import android.widget.ListView; import android.widget.TextView; public class SearchActivity extends Activity { public void onCreate(Bundle sav
package com.finalyearproject.cookmefood;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.TextView;
public class SearchActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView recipes = (ListView)findViewById(R.id.recipes);
}
}
这给了我一个错误“id无法解析”
我已经尝试清理项目,但这导致我在文件中创建错误,目前还可以
我的XML是:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<ListView
android:id="@+id/recipes"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:entries="@array.recipes"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
如果有任何帮助,我将不胜感激,我能从这里走到哪里
@array.xml中的recipes
应该是@array/recipes
这样一个简单的输入将阻止您的
R
类生成,这意味着您找不到任何id或其他资源。您还应该确保在使用android.R和您的
R
时获得正确的R
使用此com.finalyearproject.cookmefood.R.id.recipes。尝试清理和重建您的代码。我不知道为什么,但它对我起了作用。我做了此更改,但我仍然得到了以前的错误。@JamesMichaelLucas正确,请检查您的其他资源,以确保它们都是正确的。看起来你可能在某处有另一个打字错误。我不认为这是一个问题,因为上面我正在访问“R.layout.main”。这个错误是否可能来自XML中的布局?我是新的标签,线性布局的位置会导致一些错误吗?