开发者

Adding a ListView causes the Android App to crash

开发者 https://www.devze.com 2023-02-23 11:34 出处:网络
I have a problem which seems to weird. The Android application I created is running fine, but when I added a \"ListView\" element in my layout.xml file.

I have a problem which seems to weird.

The Android application I created is running fine, but when I added a "ListView" element in my layout.xml file. and I still haven't used the ListView in my java class the application refuses to startup. It simply craches and gives me this Msg : The application Client (process com.example) has stopped unexpectedly. Please try again.

This is 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>

Note: I'm testing on an Android device and not the emulator Here is a Screenshot of the error I get in logcat: http://img852.images开发者_Go百科hack.us/i/screenshotgg.png/

And finally found the sill mistake which caused it not to work I declared 2 widgets with the same id.

Thnx alot in advance.


You need to close the LinearLayout. Add </LinearLayout> to the end of the xml.

Edit: I see that you've uploaded the log. The problem is in your onCreate-method on line 42. Please post this method.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号