问题描述
我已经成功地显示一个TextView现有用户。但它只能显示一次,所以我决定使用列表视图。
I've managed to show existing user in a textview. But it can only show one at a time so I decided to use listview.
package log1.log2;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.SimpleCursorAdapter;
public class AdminMain extends ListActivity {
DBAdapter db = new DBAdapter(this);
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
db = new DBAdapter(this);
db.open();
Cursor c = db.getAllUser();
while (c.moveToNext()){
setListAdapter(new SimpleCursorAdapter(this,
R.layout.adminmain, c,
new String[] { "Username" },
new int[] {R.id.txtUser}));
}
db.close();
}
}
但是我收到的logcat此错误消息。
But I received this error message from the logcat.
08-19 04:22:49.331: ERROR/AndroidRuntime(918): java.lang.RuntimeException: Unable to start activity ComponentInfo{log1.log2/log1.log2.AdminMain}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
我在listview.xml添加列表视图。我不明白为什么错误味精告诉我。
I have added listview in listview.xml. I do not understand why the error msg tells me that.
我希望能很快收到回复有帮助!非常感谢你!
I hope to receive helpful replies soon! Thank you very much!
-Dayne
大家好
有关我的XML,我有两个xml文件,使列表视图的工作。首先是 listview.xml
和第二个是 adminmain.xml
。对于 listview.xml
,我已经放在的只列表视图的。和 adminmain.xml
,我把 的TextView 的
For my xml, I got two xml file to make the listview work. First is listview.xml
and second is adminmain.xml
. For listview.xml
, i've placed only listview. And for adminmain.xml
, I placed textview.
listview.xml
:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ListView android:id="@+id/ListView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</AbsoluteLayout>
adminmain.xml
:
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout
android:id="@+id/widget0"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background = "@drawable/image"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TextView
android:id="@+id/txtUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff000000"
android:text="USERNAMES HERE"
android:layout_x="100px"
android:layout_y="102px"/>
</AbsoluteLayout>
我试着调换 R.layout
。出现相同的错误消息。
I've tried swapping the R.layout
. The same error message appears.
我希望有人能尽快给我一个很好的提示。感谢您阅读我的文章。
I hope somebody can give me a good tip soon. Thank you for reading my post.
-Dayne
下面是从日志猫消息:
08-20 04:06:45.326: INFO/ActivityManager(587): Start proc log1.log2 for activity log1.log2/.AdminMain: pid=761 uid=10022 gids={}
08-20 04:06:45.456: DEBUG/dalvikvm(753): LinearAlloc 0x0 used 637060 of 4194304 (15%)
08-20 04:06:49.026: DEBUG/dalvikvm(761): GC freed 3633 objects / 145376 bytes in 166ms
08-20 04:06:51.876: WARN/System.err(658): Can't dispatch DDM chunk 46454154: no handler defined
08-20 04:06:51.886: WARN/System.err(658): Can't dispatch DDM chunk 4d505251: no handler defined
08-20 04:06:51.895: INFO/jdwp(676): received file descriptor 27 from ADB
08-20 04:06:51.926: INFO/jdwp(687): received file descriptor 27 from ADB
08-20 04:06:55.227: WARN/ActivityManager(587): Launch timeout has expired, giving up wake lock!
08-20 04:06:55.757: WARN/ActivityManager(587): Activity idle timeout for HistoryRecord{4367c578 {log1.log2/log1.log2.AdminMain}}
08-20 04:06:56.206: DEBUG/dalvikvm(761): GC freed 3325 objects / 126264 bytes in 142ms
08-20 04:06:56.927: WARN/System.err(687): Can't dispatch DDM chunk 46454154: no handler defined
08-20 04:06:56.927: WARN/System.err(687): Can't dispatch DDM chunk 4d505251: no handler defined
08-20 04:06:56.957: WARN/System.err(676): Can't dispatch DDM chunk 46454154: no handler defined
08-20 04:06:56.957: WARN/System.err(676): Can't dispatch DDM chunk 4d505251: no handler defined
08-20 04:06:56.967: INFO/jdwp(692): received file descriptor 33 from ADB
08-20 04:06:57.026: INFO/jdwp(707): received file descriptor 25 from ADB
08-20 04:06:57.066: WARN/System.err(692): Can't dispatch DDM chunk 46454154: no handler defined
08-20 04:06:57.066: WARN/System.err(692): Can't dispatch DDM chunk 4d505251: no handler defined
08-20 04:07:04.906: WARN/System.err(707): Can't dispatch DDM chunk 46454154: no handler defined
08-20 04:07:04.936: WARN/System.err(707): Can't dispatch DDM chunk 4d505251: no handler defined
08-20 04:07:04.957: INFO/jdwp(761): received file descriptor 26 from ADB
08-20 04:07:05.546: DEBUG/dalvikvm(658): GC freed 2935 objects / 166312 bytes in 264ms
08-20 04:07:09.946: DEBUG/dalvikvm(761): GC freed 3289 objects / 117368 bytes in 170ms
08-20 04:07:10.607: DEBUG/dalvikvm(692): GC freed 3379 objects / 202040 bytes in 326ms
08-20 04:07:15.486: DEBUG/dalvikvm(633): GC freed 2236 objects / 120792 bytes in 205ms
08-20 04:07:16.897: WARN/System.err(761): Can't dispatch DDM chunk 46454154: no handler defined
08-20 04:07:16.897: WARN/System.err(761): Can't dispatch DDM chunk 4d505251: no handler defined
08-20 04:07:30.386: DEBUG/dalvikvm(761): GC freed 4161 objects / 124992 bytes in 184ms
08-20 04:07:35.147: WARN/WindowManager(587): No window to dispatch pointer action 0
08-20 04:07:35.246: WARN/WindowManager(587): No window to dispatch pointer action 1
08-20 04:07:35.346: WARN/WindowManager(587): No window to dispatch pointer action 0
08-20 04:07:35.466: WARN/WindowManager(587): No window to dispatch pointer action 1
08-20 04:07:35.707: WARN/WindowManager(587): No window to dispatch pointer action 0
08-20 04:07:35.827: WARN/WindowManager(587): No window to dispatch pointer action 1
每次当我点击空白处,就会出现此错误信息;
Everytime when I click on the empty space, this error message will appear ;
08-20 04:07:35.707: WARN/WindowManager(587): No window to dispatch pointer action 0
08-20 04:07:35.827: WARN/WindowManager(587): No window to dispatch pointer action 1
感谢你这么多你的时间阅读本!我AP preciate它!
Thank you so much for taking your time reading this! I appreciate it!!
-Dayne
推荐答案
请问在ListView具有属性的错误消息描述的?
Does the listView has the attribute as described in the error message?
<ListView android:id="@android:id/list" ...
这篇关于列表视图错误无法运行;强制关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!