简体   繁体   中英

Caused by: java.lang.ClassNotFoundException with MaterialList

I am getting a Caused by: java.lang.ClassNotFoundException: Didn't find class "com.dexafree.materiallistviewexample.view.MaterialListView" error when running my app. I am using this library https://github.com/dexafree/MaterialList . Here is my code. I want to be sure I am not doing something wrong before I post an issue on Github. Thanks!

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'
    }
}

Welcome to StackOverflow, change the package in your FragmentTab1.xml :

from :

com.dexafree.materiallistviewexample.view.MaterialListView

to:

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>

Problem 1

Check the path of 1MaterialListView`. Seems you are using wrong path.

Problem 2

Change the id of your listview to this

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

or extend Fragment rather than ListFragment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM