use of cn.jeesoft.qa.error.QAInstantiationException 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);
}
}
Aggregations