java - 由 MaterialList 的 : java. lang.ClassNotFoundException 引起

标签 java android android-fragments

运行我的应用程序时,我收到Caused by: java.lang.ClassNotFoundException: Did not 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>

构建.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'
    }
}

最佳答案

问题1

检查1MaterialListView`的路径。看来您使用了错误的路径。

问题2

将 ListView 的 id 更改为此

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

或扩展Fragment而不是ListFragment

关于java - 由 MaterialList 的 : java. lang.ClassNotFoundException 引起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28196818/

相关文章:

java - 带 FAB 的模态 Bottom Sheet

Android HTTPS 连接基础

android - 如何知道我的 ListView 何时到达底部

java - 子 fragment 的 getView 返回 null

android - 在 fragment 中,如何停止ZXing Scanner的摄像头?

android - fragmentTransaction.add 和 fragmentTransaction.replace 之间的区别

java - 如何修改 GridData 的 heightHint

java - 语法错误,插入 ";"来完成 BlockStatements GreenDroid

java - MongoDB 日期时间插入没有从 java 完美发生

java - Android - 位图空对象引用