R.id无法解析。 Android系统。
问题描述:
我已经得到了代码:R.id无法解析。 Android系统。
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.recipes
在xml中应该是@array/recipes
。
像这样的一个简单的错字将阻止你的R
类建立意义,你不能找到任何id或其他资源。
你也应该确保你得到正确的R
你同时使用android.R
和你R
答
使用此com.finalyearproject.cookmefood.R.id.recipes。
答
尝试清理并重建您的代码。我不知道为什么,但它对我有用。
我做了这个改变,但我仍然得到以前的错误。 – 2012-04-19 14:57:50
@JamesMichaelLucas对,检查你的其他资源,确保它们都是正确的。看起来您可能在某处有另一个错字。 – Jave 2012-04-19 15:00:16
检查你的问题查看更多的错误 – WarrenFaith 2012-04-19 15:00:22