0

我一直在AlertDialog显示联系人的问题,我想我已经找到了 的问题,但我仍然感到困惑。我的代码的相关犯罪嫌疑人的部分是:SimpleCursorAdapter期待什么样的xml?

SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, 
     android.R.layout.simple_list_item_1, mContacts, 
     new String[] { ContactsContract.Contacts.DISPLAY_NAME }, 
     new int[] { android.R.id.text1 }); 

...现在“simple_list_item_1管理”是由编译器(在模拟器中运行的应用程序)所接受,但是当我 尝试运行此ListActivity,它的炸弹。

因此,在阅读其他地方关于如何完成这项任务后,我的眼睛点燃了上述“simple_list_item_1” - 那是哪里?我没有创建任何simple_list_item_1.xml文件,并且它不存在于我的\ res \ layout文件夹中。所以我(在Eclipse中)右键单击“simple_list_item_1”并选择“Open Declaration”,它调用了一个err msg,它非常类似于我在Debug Perspective中看到的关于“Class File Editor | Source nout found | JAR文件” ... \ android.jar没有源代码附件。“

所以...假设这是问题(在我的\ res \ layout文件夹中没有“simple_list_item_1.xml”),那么这个文件中的预期究竟是什么(我认为它只是一个xml定义,想要每个联系人显示在)?

==============

下面是一些logcat的数据:

以下是logcat的最后一行(好像死/挂机,一旦它到达在ListActivity(ContactsActivity):

com.aXX3AndSpace.KeepInTouch/.KeepInTouchActivity: +5s368ms 
01-08 21:54:34.020: I/ActivityManager(61): Starting: Intent { cmp=com.aXX3AndSpace.KeepInTouch/.ContactsActivity } from pid 385 

...这都是在一个试图进行错误的MSG的(打开应用程序,尝试调用ListActivity)注意“这应该不会发生”味精的。结束:

01-08 21:53:36.592: E/Zygote(33): setreuid() failed. errno: 2 
01-08 21:53:46.423: E/Zygote(33): setreuid() failed. errno: 17 
01-08 21:53:47.842: E/BatteryService(61): usbOnlinePath not found 
01-08 21:53:47.842: E/BatteryService(61): batteryVoltagePath not found 
01-08 21:53:47.842: E/BatteryService(61): batteryTemperaturePath not found 
01-08 21:53:47.862: E/SurfaceFlinger(61): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake 
01-08 21:53:48.082: E/SensorService(61): couldn't open device for module sensors (Invalid argument) 
01-08 21:53:53.722: E/System(61): Failure starting core service 
01-08 21:53:53.722: E/System(61): java.lang.SecurityException 
01-08 21:53:53.722: E/System(61): at android.os.BinderProxy.transact(Native Method) 
01-08 21:53:53.722: E/System(61): at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146) 
01-08 21:53:53.722: E/System(61): at android.os.ServiceManager.addService(ServiceManager.java:72) 
01-08 21:53:53.722: E/System(61): at com.android.server.ServerThread.run(SystemServer.java:207) 
01-08 21:53:53.742: E/EventHub(61): could not get driver version for /dev/input/mouse0, Not a typewriter 
01-08 21:53:53.742: E/EventHub(61): could not get driver version for /dev/input/mice, Not a typewriter 
01-08 21:53:54.032: E/SoundPool(61): error loading /system/media/audio/ui/Effect_Tick.ogg 
01-08 21:53:54.032: E/SoundPool(61): error loading /system/media/audio/ui/KeypressStandard.ogg 
01-08 21:53:54.032: E/SoundPool(61): error loading /system/media/audio/ui/KeypressSpacebar.ogg 
01-08 21:53:54.042: E/SoundPool(61): error loading /system/media/audio/ui/KeypressDelete.ogg 
01-08 21:53:54.042: E/SoundPool(61): error loading /system/media/audio/ui/KeypressReturn.ogg 
01-08 21:53:54.703: E/ThrottleService(61): Could not open GPS configuration file /etc/gps.conf 
01-08 21:53:57.172: E/logwrapper(158): executing /system/bin/tc failed: No such file or directory 
01-08 21:53:57.242: E/logwrapper(159): executing /system/bin/tc failed: No such file or directory 
01-08 21:53:57.282: E/logwrapper(160): executing /system/bin/tc failed: No such file or directory 
01-08 21:54:00.074: E/jdwp(174): Failed sending reply to debugger: Broken pipe 
01-08 21:54:00.712: E/Database(116): sqlite_config failed error_code = 21. THIS SHOULD NEVER occur. 
+0

错误?它是否存在?请张贴崩溃日志 – nandeesh 2012-01-08 16:20:34

+0

如何保存崩溃日志?我看到一个“保存选定的行”选项,但一定有一种方法来一次保存它们(全选),但我没有看到它... – 2012-01-08 18:14:31

+0

是的,我正在访问_id列: String [ ] projection = new String [] {ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME}; ... int selectedId = mContacts。getInt(0); // _ID列 ... ContactsContract.Data.CONTACT_ID +“=”+ selectedId,null,null); ... ContactsContract.Data.CONTACT_ID +“=”+ selectedId,null,null); ... ContactsContract.Data.CONTACT_ID +“=”+ selectedId,null,null); – 2012-01-08 18:19:42

回答

2

simple_list_item_1是在SDK中定义的标准布局,它基本上只是一个TextView,ID为“android:id/text1”,这是您在视图标识符中提供的内容。

你有坠毁的堆栈跟踪?因为这很可能不是由于缺少simple_list_item_1布局。

+0

当我选择“导出选定的项目到文本文件”时,没有任何内容导出(来自LogCat);我该如何做一个“全选”? – 2012-01-08 18:25:50

+0

相当有点“本质”在这里:http://stackoverflow.com/questions/8767184/listactivity-starts-but-then-fails-almost-immediately – 2012-01-08 18:27:38

1

使用Eclipse向导创建一个新的XML布局文件。该文件的名称将在你的代码替换simple_list_item_1

在这种布局中,创建一个TextView(或任何其他容器)元素,并调用它text1

然后SimpleCursorAdaptor将匹配您的联系方式和text1场在您的布局,如果你的光标投影不含_ID列可发生

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 
<TextView 
    android:id="@+id/text1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="TextView" /> 

+0

它有助于解决您的问题? – znat 2012-01-08 20:19:00