user1927638
user1927638

Reputation: 1173

DragSortListView Library and DropListener in ListFragment Class

I am currently trying to implement the DSLV library into my ListFragment class and I am getting the error

04-28 17:43:13.876: E/AndroidRuntime(17113): FATAL EXCEPTION: main
04-28 17:43:13.876: E/AndroidRuntime(17113): java.lang.NoClassDefFoundError:         com.main.tab.FavoritesTab$1
04-28 17:43:13.876: E/AndroidRuntime(17113):    at com.main.tab.FavoritesTab.<init>(FavoritesTab.java:43)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at com.main.transit.MainActivity.onCreate(MainActivity.java:85)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at android.app.Activity.performCreate(Activity.java:5104)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2261)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2357)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at android.app.ActivityThread.access$600(ActivityThread.java:153)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at android.os.Handler.dispatchMessage(Handler.java:99)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at android.os.Looper.loop(Looper.java:137)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at android.app.ActivityThread.main(ActivityThread.java:5226)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at java.lang.reflect.Method.invokeNative(Native Method)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at java.lang.reflect.Method.invoke(Method.java:511)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
04-28 17:43:13.876: E/AndroidRuntime(17113):    at dalvik.system.NativeStart.main(Native Method)

According to the error, it would appear that line 43 is causing a java.lang.NoClassDefFoundError:. It seems that declarations of the DropListener is causing the issue. Could it also be caused by a declaration I've made in the xml file? Here is the source code:

public class FavoritesTab extends ListFragment
{
private JazzAdapter adapter;

private ArrayList<JazzArtist> mArtists;

private String[] mArtistNames = {"Brighouse Stn Bay 7", "Nb No.3 Rd Fs Francis Rd", "Sb Westbrook Mall Fs University--"};
private String[] mArtistAlbums = {"402: 1:40pm, 2:10pm\n403: 1:39pm, 2:01pm, 2:22pm\n404: 1:46pm, 2:16pm\n410: 1:39pm, 1:50pm, 2:09pm, 2:19pm, 2:23pm\n",
        "403: 1:53pm, 2:13pm, 2:33pm\n",
        "025: 1:38pm, 1:50pm, 2:02pm, 2:14pm, 2:26pm\n033: 2:01pm, 2:31pm\n041: 1:45pm, 2:08pm, 2:25pm\n"};
private String[] mStops = {"56549", "56616", "61598"};

private DragSortListView.DropListener onDrop =
    new DragSortListView.DropListener() {
        @Override
        public void drop(int from, int to) {
            JazzArtist item = adapter.getItem(from);

            adapter.remove(item);
            adapter.insert(item, to);
        }
    };

private DragSortListView.RemoveListener onRemove = 
    new DragSortListView.RemoveListener() {
        @Override
        public void remove(int which) {
            adapter.remove(adapter.getItem(which));
        }
    };

/** Called when the activity is first created. */
 @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        MainActivity ma = (MainActivity) getActivity();

        DragSortListView lv = (DragSortListView) getListView(); 

        lv.setDropListener(onDrop);
        lv.setRemoveListener(onRemove);

        mArtists = new ArrayList<JazzArtist>();

        for(int i=0; i<3; i++) {
            JazzArtist ja = new JazzArtist();
            ja.name = mArtistNames[i];
            ja.albums = mArtistAlbums[i];
            ja.stop_no = mStops[i];
            mArtists.add(ja);
        }

        adapter = new JazzAdapter(mArtists);

        setListAdapter(adapter);

        //ma.refreshList();
    }

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState)
{
    View view = inflater.inflate(R.layout.activity_favorites_tab, container, false);
    return view;
}

private class JazzArtist {
      public String name;
      public String albums;
      public String stop_no;

      @Override
      public String toString() {
        return name;
      }
    }

    private class ViewHolder {
      public TextView albumsView;
      public TextView stopNo;
    }

    private class JazzAdapter extends ArrayAdapter<JazzArtist> {

      public JazzAdapter(List<JazzArtist> artists) {
        super(getActivity(), R.layout.jazz_artist_list_item,
          R.id.artist_name_textview, artists);
      }

      public View getView(int position, View convertView, ViewGroup parent) {
        View v = super.getView(position, convertView, parent);

        if (v != convertView && v != null) {
          ViewHolder holder = new ViewHolder();

          TextView tv = (TextView) v.findViewById(R.id.artist_albums_textview);
          TextView tv2 = (TextView) v.findViewById(R.id.stop_number_textview);
          holder.albumsView = tv;
          holder.stopNo = tv2;

          v.setTag(holder);
        }

        ViewHolder holder = (ViewHolder) v.getTag();
        String albums = getItem(position).albums;
        String stop_no = "Bus Stop " + getItem(position).stop_no;

        holder.albumsView.setText(albums);
        holder.stopNo.setText(stop_no);

        return v;
      }
    }

}

edit - As it turns out, I didn't import the library properly. However, I am now presented with a new issue. I am getting the error

04-28 21:19:34.786: E/AndroidRuntime(32514): FATAL EXCEPTION: main
04-28 21:19:34.786: E/AndroidRuntime(32514): android.view.InflateException: Binary XML file line #8: Error inflating class com.mobeta.android.dslv.DragSortListView

Here is my XML layout:

<?xml version="1.0" encoding="utf-8"?>
<com.mobeta.android.dslv.DragSortListView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:dslv="http://schemas.android.com/apk/res-auto"
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingTop="7dp"
    android:paddingBottom="0dp"
    android:paddingLeft="0dp"
    android:layout_margin="0dp"
    android:dividerHeight="5dp"
    dslv:drag_enabled="true"
    dslv:collapsed_height="2dp"
    dslv:drag_scroll_start="0.33"
    dslv:max_drag_scroll_speed="0.5"
    dslv:float_alpha="0.6"
    dslv:slide_shuffle_speed="0.3"
    dslv:track_drag_sort="false"
    dslv:use_default_controller="true"
    dslv:sort_enabled="false"
    dslv:remove_enabled="true"
    dslv:remove_mode="flingRemove"
    android:background="#E5E5E5" />

If I change the line "xmlns:android="http://schemas.android.com/apk/res/android"" to " xmlns:dslv="http://schemas.android.com/apk/res/com.mobeta.android.demodslv" ", I will get a "No resource ifentifier found" error.

Upvotes: 0

Views: 1495

Answers (3)

Eddie
Eddie

Reputation: 41

You might have the wrong url. It should be : http://schemas.android.com/apk/lib/com.mobeta.android.dslv You are hitting the demo project with "com.mobeta.android.demodslv"

Upvotes: 1

Sohyun Ahn
Sohyun Ahn

Reputation: 250

Which version of android do you use? ListFragment can be used in version 11. You have to add the 'support.v4.jar'.

Upvotes: 0

Parvaz Bhaskar
Parvaz Bhaskar

Reputation: 1367

It seems that your DragSortListView is not added as a library in the project. It is not always necessary to include a jar in project libs. Sometimes a whole project can be used as library. Check in the demos if it includes the DSLV project by checking the properties-->Android under library.

Upvotes: 0

Related Questions