Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import dalvik.system.PathClassLoader;

import android.content.Context;

public class Main {

    public static Object loadClass(Context context, String path) {
        try {
            String dexPath = context.getApplicationInfo().sourceDir;
            PathClassLoader pathClassLoader = new PathClassLoader(dexPath, context.getClassLoader());
            Class<?> c = Class.forName(path, true, pathClassLoader);
            Object ret = c.newInstance();
            return ret;
        } catch (InstantiationException ex1) {
            ex1.printStackTrace();
        } catch (IllegalAccessException ex2) {
            ex2.printStackTrace();
        } catch (ClassNotFoundException ex3) {
            ex3.printStackTrace();
        }

        return null;
    }
}