Search in sources :

Example 1 with QAException

use of cn.jeesoft.qa.error.QAException in project QuickAndroid by ImKarl.

the class QACore method initApp.

/**
     * 初始化方法
     * <pre>
     * initApp()仅需调用一次
     * </pre>
     * @param app {@link Application}
     * @param clazz 自定义的{@link QAApp}类型
     * @throws QAInstantiationException QAApp实例化异常
     * @see #initApp(Application)
     */
public static void initApp(Application app, Class<? extends QAApp> clazz) throws QAInstantiationException {
    // 检查QAApp是否已初始化
    try {
        if (QAApp.getApp() != null) {
            return;
        }
    } catch (QAException e) {
    }
    // 实例化QAApp
    try {
        Constructor<? extends QAApp> constructor = clazz.getConstructor(QAPrivateCheck.class, Application.class);
        QAApp newInstance = constructor.newInstance(new QAPrivateCheck() {

            public boolean check() {
                return true;
            }
        }, app);
        if (newInstance == null) {
            throw new NullPointerException("QAApp实例化失败");
        }
    } catch (NoSuchMethodException e) {
        throw new QAInstantiationException(QAException.CODE_NO_METHOD, "QAApp找不到对应的构造方法", e);
    } catch (InstantiationException e) {
        throw new QAInstantiationException(QAException.CODE_INSTANTIATION, "QAApp构造方法无法执行", e);
    } catch (IllegalAccessException e) {
        throw new QAInstantiationException(QAException.CODE_ILLEGAL_ACCESS, "QAApp构造方法非法访问", e);
    } catch (IllegalArgumentException e) {
        throw new QAInstantiationException(QAException.CODE_ILLEGAL_ARGUMENT, "QAApp构造方法参数非法", e);
    } catch (InvocationTargetException e) {
        throw new QAInstantiationException(QAException.CODE_EXECUTE, "QAApp构造方法执行异常", e.getTargetException());
    } catch (Exception e) {
        throw new QAInstantiationException(QAException.CODE_UNKNOW, "QAApp实例化失败", e);
    }
}
Also used : QAInstantiationException(cn.jeesoft.qa.error.QAInstantiationException) QAApp(cn.jeesoft.qa.app.QAApp) QAException(cn.jeesoft.qa.error.QAException) InvocationTargetException(java.lang.reflect.InvocationTargetException) QAInstantiationException(cn.jeesoft.qa.error.QAInstantiationException) QANullException(cn.jeesoft.qa.error.QANullException) QACheckException(cn.jeesoft.qa.error.QACheckException) QAException(cn.jeesoft.qa.error.QAException) InvocationTargetException(java.lang.reflect.InvocationTargetException) QAInstantiationException(cn.jeesoft.qa.error.QAInstantiationException)

Aggregations

QAApp (cn.jeesoft.qa.app.QAApp)1 QACheckException (cn.jeesoft.qa.error.QACheckException)1 QAException (cn.jeesoft.qa.error.QAException)1 QAInstantiationException (cn.jeesoft.qa.error.QAInstantiationException)1 QANullException (cn.jeesoft.qa.error.QANullException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1