添加列表视图会导致Android应用程序崩溃

添加列表视图会导致Android应用程序崩溃,android,Android,我有个奇怪的问题 我创建的Android应用程序运行良好,但当我在layout.xml文件中添加“ListView”元素时。 我还没有在java类中使用ListView,应用程序拒绝启动。 它只是简单地摇摇晃晃地告诉我这个消息:应用程序客户端(processcom.example)意外停止。请重试。 这是my layout.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:androi

我有个奇怪的问题

我创建的Android应用程序运行良好,但当我在
layout.xml
文件中添加“ListView”元素时。 我还没有在java类中使用ListView,应用程序拒绝启动。 它只是简单地摇摇晃晃地告诉我这个消息:
应用程序客户端(processcom.example)意外停止。请重试。

这是my 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>

注意:我是在安卓设备上测试的,不是模拟器 下面是我在logcat中得到的错误截图:

最后发现了导致它无法工作的窗台错误 我声明了两个具有相同id的小部件


提前很多时间。您需要关闭线性布局。将
添加到xml的末尾


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

请发布您的
layout.xml
请提供
layout.xml
和错误报告/堆栈跟踪(如果您正在使用Eclipse,可以在DDMS或Debug中找到。您在
FtpClient.java
中有一个
onCreate
抛出的
ClassCastException
。请发布
onCreate
方法的代码,并指出第42行。既然您说您只添加了一个列表视图而没有触及代码,我建议您这样做一个干净的构建,然后重试。如果你在我发布的代码中向下滚动,它已经被添加。你会找到它。这是onCreate:list=(ListView)findViewById(R.id.list)中的第42行;我的结论可能有点快。也就是说,如果
列表
应该是一个列表,那么这就是解决方案。你能发布
列表
的声明吗?
列表
定义为
列表
?我就是这样声明的——ListView列表;