Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.view.ViewGroup;

public class Main {
    private static final String RECYCLERVIEW_CLASS_NAME = "android.support.v7.widget.RecyclerView";

    public static void checkRecyclerView(ViewGroup recyclerView) {
        checkRecyclerViewOnClassPath();

        Class clazz = recyclerView.getClass();
        while (clazz != null) {
            if (clazz.getName().equals(RECYCLERVIEW_CLASS_NAME)) {
                return;
            }
            clazz = clazz.getSuperclass();
        }

        throw new IllegalArgumentException("ViewGroup " + recyclerView.getClass().getName() + " not supported");

    }

    public static void checkRecyclerViewOnClassPath() {
        if (!hasRecyclerView()) {
            throw new NoClassDefFoundError(
                    "RecyclerView is not on classpath, " + "make sure that you have it in your dependencies");
        }
    }

    static boolean hasRecyclerView() {
        try {
            Class.forName(RECYCLERVIEW_CLASS_NAME);
            return true;
        } catch (ClassNotFoundException ignored) {
            return false;
        }
    }
}