我目前正在尝试将 DSLV 库实现到我的 ListFragment 类中,但出现错误
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)
根据错误,第 43 行似乎导致了 java.lang.NoClassDefFoundError:。似乎 DropListener 的声明导致了这个问题。它也可能是由我在 xml 文件中所做的声明引起的吗?这是源代码:
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;
}
}
}
编辑 - 事实证明,我没有正确导入库。然而,我现在遇到了一个新问题。我收到错误
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
这是我的 XML 布局:
<?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" />
如果我将“xmlns:android="http://schemas.android.com/apk/res/android"”行更改为“xmlns:dslv="http://schemas.android.com/apk/res/com .mobeta.android.demodslv" ",我会得到一个“No resource ifentifier found”错误。