引起:与MaterialList的java.lang.ClassNotFoundException

时间:2015-01-28 16:01:56

标签: java android android-fragments

运行我的应用时出现Caused by: java.lang.ClassNotFoundException: Didn't find class "com.dexafree.materiallistviewexample.view.MaterialListView"错误。我正在使用这个库https://github.com/dexafree/MaterialList。这是我的代码。在Github发布问题之前,我想确定我没有做错。谢谢!

Fragment1.java:

public class  FragmentTab1 extends ListFragment {

private Context mContext;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragmenttab1, null);

    mContext = getActivity();
    MaterialListView mListView = (MaterialListView) view.findViewById(R.id.material_listview);

    SimpleCard card = new SmallImageCard(mContext);
    card.setDescription("Description");
    card.setTitle("Title");
    card.setDrawable(R.drawable.ic_launcher);

    mListView.add(card);

    return view;

}

FragmentTab1.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">

<com.dexafree.materiallistviewexample.view.MaterialListView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/material_listview"/>

</RelativeLayout>

的build.gradle:

    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile ('com.github.dexafree:materiallist:2.0.1') {
        exclude group: 'com.nhaarman.listviewanimations'
    }
}

2 个答案:

答案 0 :(得分:0)

欢迎使用StackOverflow,更改FragmentTab1.xml

中的包

来自:

com.dexafree.materiallistviewexample.view.MaterialListView

为:

com.dexafree.materiallist.view.MaterialListView

FragmentTab1.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">

<com.dexafree.materiallist.view.MaterialListView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/material_listview"/>

</RelativeLayout>

答案 1 :(得分:0)

问题1

检查1MaterialListView`的路径。似乎你使用了错误的路径。

问题2

将列表视图的ID更改为此

android:id="@android:id/list"

或延伸Fragment而不是ListFragment