2

我试图在我的项目中使用Swipelistview但它抛出 NullPointer 说:

java.lang.NullPointerException
at com.fortysevendeg.swipelistview.SwipeListViewTouchListener.setFrontView(SwipeListViewTouchListener.java:138)
at com.fortysevendeg.swipelistview.SwipeListViewTouchListener.onTouch(SwipeListViewTouchListener.java:731)
at com.fortysevendeg.swipelistview.SwipeListView.onInterceptTouchEvent(SwipeListView.java:630)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1852)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910)   

  在 android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209) 在 android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1910) 在 android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2209)

我通过以下方式实现了该库:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.fortysevendeg.swipelistview.SwipeListView
        xmlns:swipe="http://schemas.android.com/apk/res-auto"
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="35dp"
        android:layout_marginTop="51dp"
        android:listSelector="#00000000"
        swipe:swipeActionLeft="dismiss"
        swipe:swipeActionRight="dismiss"
        swipe:swipeAnimationTime="1000"
        swipe:swipeBackView="@+id/back"
        swipe:swipeCloseAllItemsWhenMoveList="false"
        swipe:swipeFrontView="@+id/front"
        swipe:swipeMode="both"
        swipe:swipeOffsetLeft="20dp"
        swipe:swipeOffsetRight="20dp"
        swipe:swipeOpenOnLongPress="false" />  

</LinearLayout>

这是代码:

private SwipeListView listview1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);

        States states_name[] = new States[] {
                new States("Item 1", "Item A"),
                new States("Item 2", "Item B"),
                new States("Item 3", "Item C"),
                new States("Item 4", "Item D"),
                new States("Item 5", "Item E"),
                new States("Item 6", "Item F"), 
                new States("Item 7", "Item G"),
                new States("Item 8", "Item H")
        };

        StateAdapter adapter = new StateAdapter(this, R.layout.listtoinflate, states_name);

        listview1 = (SwipeListView)findViewById(R.id.listView1);
     listview1.setAdapter(adapter);


    }

 

4

2 回答 2

0

shouldn't this...

States states_name[] = new States[]

be this?...

States[] states_name = new States[]
于 2013-10-28T15:47:36.483 回答
0

您可能缺少布局中 com.fortysevendeg.swipelistview.SwipeListView 的实现中指定的 id 为“front”和“back”的元素。它们应该在列表视图行布局中,在您的情况下应该是“R.layout.listtoinflate”,您在适配器中有。

这里有一些示例代码: https ://github.com/47deg/android-swipelistview-sample/blob/master/res/layout/package_row.xml

这个问题也在这个线程中得到解答: SwipeListView 用法 NullPointerException

于 2014-10-15T07:21:34.790 回答