R.id不能在Android ListActivity解决 [英] R.id cannot be resolved on android ListActivity
问题描述
我得到这个奇怪的错误:
I am getting this strange error:
R.id cannot be resolved
这行:
WebView myWebView = (WebView) findViewById(view.R.id.webview);
myWebView.loadUrl(s);
我试图清理项目,并重新启动。
这里是我的code:
I tried to clean the project and restart it. here is my code:
public class NewsActivity extends ListActivity {
public ReadXML ReadXML=new ReadXML();
public ArrayList<String> ynetList =new ArrayList<String>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
for(int i=0;i<ReadXML.hadashotListItems.size();i++)
ynetList.add(ReadXML.hadashotListItems.get(i).title+"\n"+ReadXML.hadashotListItems.get(i).pubDate);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, ynetList));
// setContentView(R.layout.main);
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
// When clicked, show a toast with the TextView text
String s= ReadXML.hadashotListItems.get(position).link;
WebView myWebView = (WebView) findViewById(view.R.id.webview);
myWebView.loadUrl(s);
//
//Toast.makeText(getApplicationContext(((TextView)view).getText(),Toast.LENGTH_SHORT).show();
}
}
);
}}
我的XML code是:
list_item.xml
my xml code is: list_item.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"
>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="15sp" >
</TextView>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
感谢您的帮助!
推荐答案
消息 R.id无法解析
表示研究
类是不正确建立,或者至少是不能根据文件 list_item.xml
,因为它定义了一个 ID
。
The message R.id cannot be resolved
means that the R
class is not properly built or at least is not according to your file list_item.xml
as it defines an id
.
可能的原因有以下几点:
The probable causes are the following:
-
Eclipse是丢失,不管理才能正确地构建您的项目(这种情况发生的某个时候):尝试清理和重建项目(菜单项目/干净的Eclipse)。
Eclipse is lost and does not manage to build your project properly (this happens sometime): try to clean and rebuild your project (menu project/clean of Eclipse).
有时候,这是不够要么,所以尽量
Sometimes this is not sufficient either, so try to
- 清洁你的项目
- 修改
的AndroidManifest.xml
通过添加它的空白字符 - 关闭项目在Eclipse
- 再次打开它
- 重新清理,并建立它
- clean you project
- modify your
AndroidManifest.xml
by adding a blank char in it - Close your project in Eclipse
- Open it again
- Re-clean it and build it
-
您文件
list_item.xml
是不是在正确的目录。它应该是在目录[project_root] / RES /布局
Your file
list_item.xml
is not in the right directory. It should be in the directory[project_root]/res/layout
您有一个Android框架的安装问题。检查菜单的Eclipse的Windows / Android SDK和ADT经理是否一切正常。
You have an Android framework installation problem. Check in the menu "Windows/Android SDK and ADT manager" of Eclipse whether everything is fine.
这篇关于R.id不能在Android ListActivity解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!