android - Listview selection crashes app -
i have listview listed below. when select first value in listview works fine. however, anytime select other first listview value app crashes. not sure causing this. thanks.
<android.support.v4.widget.drawerlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" > <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <linearlayout android:id="@+id/container_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <include android:id="@+id/toolbar" layout="@layout/toolbar" /> </linearlayout> <framelayout android:id="@+id/container_body" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" android:fitssystemwindows="true" android:cliptopadding="false" /> <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/txt_empty_list_cars" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerinparent="true" android:layout_margin="4dp" android:gravity="center" android:text="@string/no_cars_in_db" android:textappearance="?android:attr/textappearance" android:textcolor="@android:color/darker_gray" android:visibility="gone" /> <listview android:id="@+id/list_cars" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/container_body" android:layout_margin="4dp" android:divider="@android:drawable/divider_horizontal_bright" android:dividerheight="0.5dp" android:listselector="@android:drawable/list_selector_background" /> </linearlayout> </linearlayout> <fragment android:id="@+id/fragment_navigation_drawer" android:name=“com.example.my.app.fragmentdrawer" android:layout_width="@dimen/nav_drawer_width" android:layout_height="match_parent" android:layout_gravity="start" android:layout="@layout/fragment_navigation_drawer" tools:layout="@layout/fragment_navigation_drawer" /> </android.support.v4.widget.drawerlayout>
logcat below:
08-19 11:56:32.598 1943-1943/com.example.my.app e/androidruntime﹕ fatal exception: main process: com.example.my.app, pid: 1943 android.database.cursorindexoutofboundsexception: index 0 requested, size of 0 @ android.database.abstractcursor.checkposition(abstractcursor.java:426) @ android.database.abstractwindowedcursor.checkposition(abstractwindowedcursor.java:136) @ android.database.abstractwindowedcursor.getint(abstractwindowedcursor.java:68) @ com.example.my.app.listcarsadapter.getview(listcarsadapter.java:71) @ android.widget.abslistview.obtainview(abslistview.java:2344) @ android.widget.listview.makeandaddview(listview.java:1864) @ android.widget.listview.filldown(listview.java:698) @ android.widget.listview.fillfromtop(listview.java:759) @ android.widget.listview.layoutchildren(listview.java:1673) @ android.widget.abslistview.onlayout(abslistview.java:2148) @ android.view.view.layout(view.java:15596) @ android.view.viewgroup.layout(viewgroup.java:4966) @ android.widget.relativelayout.onlayout(relativelayout.java:1076) @ android.view.view.layout(view.java:15596) @ android.view.viewgroup.layout(viewgroup.java:4966) @ android.widget.linearlayout.setchildframe(linearlayout.java:1703) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1557) @ android.widget.linearlayout.onlayout(linearlayout.java:1466) @ android.view.view.layout(view.java:15596) @ android.view.viewgroup.layout(viewgroup.java:4966) @ android.support.v4.widget.drawerlayout.onlayout(drawerlayout.java:907) @ android.view.view.layout(view.java:15596) @ android.view.viewgroup.layout(viewgroup.java:4966) @ android.widget.framelayout.layoutchildren(framelayout.java:573) @ android.widget.framelayout.onlayout(framelayout.java:508) @ android.view.view.layout(view.java:15596) @ android.view.viewgroup.layout(viewgroup.java:4966) @ android.widget.linearlayout.setchildframe(linearlayout.java:1703) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1557) @ android.widget.linearlayout.onlayout(linearlayout.java:1466) @ android.view.view.layout(view.java:15596) @ android.view.viewgroup.layout(viewgroup.java:4966) @ android.widget.framelayout.layoutchildren(framelayout.java:573) @ android.widget.framelayout.onlayout(framelayout.java:508) @ android.view.view.layout(view.java:15596) @ android.view.viewgroup.layout(viewgroup.java:4966) @ android.widget.linearlayout.setchildframe(linearlayout.java:1703) @ android.widget.linearlayout.layoutvertical(linearlayout.java:1557) @ android.widget.linearlayout.onlayout(linearlayout.java:1466) @ android.view.view.layout(view.java:15596) @ android.view.viewgroup.layout(viewgroup.java:4966) @ android.widget.framelayout.layoutchildren(framelayout.java:573) @ android.widget.framelayout.onlayout(framelayout.java:508) @ android.view.view.layout(view.java:15596) @ android.view.viewgroup.layout(viewgroup.java:4966) @ android.view.viewrootimpl.performlayout(viewrootimpl.java:2072) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1829) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1054) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5779) @ android.view.choreographer$callbackrecord.run(choreographer.java:767) @ android.view.choreographer.docallbacks(choreographer.java:580) @ android.view.choreographer.doframe(choreographer.java:550) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:753) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5221) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:694)
it seems fill list database , cursor used return empty values
you must make check
if(cursor != null && cursor.movetofirst())
Comments
Post a Comment