我得到一个运行时异常
java.lang.RuntimeException的:你的内容必须有一个ListView的ID 属性是android.R.id.list
我不知道什么是错的。
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.newslist);
mDbHelper.open();
fillData();
}
私人无效fillData(){
捆绑额外= getIntent()getExtras()。
长CATID = extras.getLong(cat_id);
光标C = mDbHelper.fetchNews(CATID);
startManagingCursor(C);
的String []从=新的String [] {DBHelper.KEY_TITLE};
INT []到=新INT [] {R.id.newslist_text};
SimpleCursorAdapter注意到=新SimpleCursorAdapter(这一点,R.layout.text_newslist,C,从,到);
setListAdapter(票据);
}
newslist.xml
< XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
<的ListView
机器人:ID =@ + ID / catnewslist
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
< / ListView控件>
< / LinearLayout中>
text_newslist.xml
< XML版本=1.0编码=UTF-8&GT?;
<的LinearLayout
的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
<的TextView
机器人:文本=@ + ID / newslist_text
机器人:ID =@ + ID / newslist_text
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT>
< / TextView的>
< / LinearLayout中>
解决方案
< ListView的机器人:ID =@机器人:ID /列表
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT/>
这将解决这个错误,如果你仍然想使用ListActivity。
I am getting a run time exception
java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
I don't know what is wrong.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.newslist);
mDbHelper.open();
fillData();
}
private void fillData() {
Bundle extras = getIntent().getExtras();
long catID = extras.getLong("cat_id");
Cursor c = mDbHelper.fetchNews(catID);
startManagingCursor(c);
String[] from = new String[] { DBHelper.KEY_TITLE };
int[] to = new int[] { R.id.newslist_text };
SimpleCursorAdapter notes = new SimpleCursorAdapter(this, R.layout.text_newslist, c, from, to);
setListAdapter(notes);
}
newslist.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ListView
android:id="@+id/catnewslist"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
text_newslist.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="@+id/newslist_text"
android:id="@+id/newslist_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</LinearLayout>
解决方案
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
This will solve the error if you still want to use a ListActivity.