Listview错误无法运行;强制关闭

时间:2010-08-19 04:28:10

标签: android xml database listview

我设法在textview中显示现有用户。但它一次只能显示一个,所以我决定使用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的错误消息。

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中添加了listview。我不明白为什么错误消息告诉我。

我希望尽快收到有用的回复!非常感谢你!

-Dayne


被修改

再次问好

对于我的xml,我有两个xml文件来使listview工作。首先是listview.xml,第二个是adminmain.xml。对于listview.xml,我只放置了 listview 。对于adminmain.xml,我放置了 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。出现相同的错误消息。

我希望有人能尽快给我一个好的建议。感谢您阅读我的帖子。

-Dayne


编辑后

以下是来自log cat的消息:

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

每次点击空白区域时,都会显示此错误消息;

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

非常感谢您花时间阅读本文!我很感激!!

-Dayne

1 个答案:

答案 0 :(得分:2)

listView是否具有错误消息中描述的属性?

<ListView android:id="@android:id/list" ...