2011-04-11 83 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

相關問題