2011-04-11 41 views
1

我有一个似乎很奇怪的问题。添加ListView会导致Android应用程序崩溃

我创建的Android应用程序运行良好,但是当我在我的layout.xml文件中添加了“ListView”元素时。 我仍然没有在我的java类中使用ListView,应用程序拒绝启动。 它只是craches,给我这个消息:The application Client (process com.example) has stopped unexpectedly. Please try again.

这是我layout.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 android:id="@+id/view" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/filename"/> 

    <ListView android:id="@+id/list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:drawSelectorOnTop="false" 
    /> 

    <EditText 
    android:id="@+id/input" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:singleLine="true" 
    /> 

    <Button 
    android:id="@+id/connect" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Connect" 
    android:onClick="Connect" 
    /> 

    <Button 
    android:id="@+id/download" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Download" 
    android:onClick="Download" 
    /> 
    <Button 
    android:id="@+id/delete" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="List" 
    android:onClick="List" 
    /> 

</LinearLayout> 

注:我的Android设备,而不是模拟器 这里对测试的一个截图错误我得到的logcat:http://img852.imageshack.us/i/screenshotgg.png/

终于找到了导致它不工作的基石错误 我宣布2个小工具具有相同的ID。

Thnx提前。

+0

请发布您的'layout.xml' – MByD 2011-04-11 16:05:16

+2

请提供'layout.xml'和错误报告/堆栈跟踪(如果您使用的是Eclipse,可以在DDMS或Debug中找到) – pecka85 2011-04-11 16:06:17

+0

您有''ClassCastException'' onCreate'在'FtpClient.java'中,请发布你的'onCreate'方法的代码并指出第42行。 – 2011-04-11 16:43:02

回答

0

您需要关闭LinearLayout。将</LinearLayout>添加到xml的末尾。

编辑:我看到你已经上传了日志。问题出在您的onCreate - 第42行。请发布此方法。

+0

它已经被添加了,如果你向下滚动到我贴的代码中,U会找到它 – 2011-04-11 16:27:43

+0

这是onCreate中的第42行: list =(ListView)findViewById(R.id.list); – 2011-04-11 16:51:36

+0

I'在我的结论中,这可能会有点快,也就是说,如果'List'应该是一个列表,那么这就是解决方案。 – pecka85 2011-04-11 16:51:52