List of usage examples for java.lang ClassNotFoundException printStackTrace
public void printStackTrace()
From source file:org.apache.hadoop.hive.serde2.protobuf.ProtobufUtils.java
public static Class<?> loadTableMsgClass(String outerName, String name) { try {//from ww w . java 2 s.co m StringBuilder fullName = new StringBuilder(); String pkgName = "tdw"; fullName.append(pkgName); fullName.append("."); ArrayList<String> pieces = new ArrayList<String>(); pieces.add(outerName); pieces.add(name); fullName.append(StringUtils.join(pieces, "$")); Class<?> cls = Class.forName(fullName.toString(), true, JavaUtils.getpbClassLoader()); return cls; } catch (java.lang.ClassNotFoundException e) { e.printStackTrace(); return null; } }
From source file:Main.java
private static int getExifOrientation(String src) throws IOException { int orientation = 1; try {//from w w w . j a v a2 s.co m /** * if your are targeting only api level >= 5 * ExifInterface exif = new ExifInterface(src); * orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); */ if (Build.VERSION.SDK_INT >= 5) { Class<?> exifClass = Class.forName("android.media.ExifInterface"); Constructor<?> exifConstructor = exifClass.getConstructor(new Class[] { String.class }); Object exifInstance = exifConstructor.newInstance(new Object[] { src }); Method getAttributeInt = exifClass.getMethod("getAttributeInt", new Class[] { String.class, int.class }); Field tagOrientationField = exifClass.getField("TAG_ORIENTATION"); String tagOrientation = (String) tagOrientationField.get(null); orientation = (Integer) getAttributeInt.invoke(exifInstance, new Object[] { tagOrientation, 1 }); } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } return orientation; }
From source file:de.fct.companian.analyze.helper.DbHelper.java
public static DataSource createDataSource(Properties properties) { String dbDriver;/*from w w w. j av a2 s. co m*/ String dbUrl; String dbUser; String dbPass; String dbDriverDefault = "com.mysql.jdbc.Driver"; String dbUrlDefault = "jdbc:mysql://localhost:3306/cpanalyze"; String dbUserDefault = "cpanalyze"; String dbPassDefault = "ezylanapc"; if (properties != null) { dbDriver = properties.getProperty("database.driver"); if (dbDriver == null) { dbDriver = dbDriverDefault; } dbUrl = properties.getProperty("database.url"); if (dbUrl == null) { dbUrl = dbUrlDefault; } dbUser = properties.getProperty("database.username"); if (dbUser == null) { dbUser = dbUserDefault; } dbPass = properties.getProperty("database.password"); if (dbPass == null && dbUser.equals("cpanalyze")) { dbPass = dbPassDefault; } } else { dbDriver = dbDriverDefault; dbUrl = dbUrlDefault; dbUser = dbUserDefault; dbPass = dbPassDefault; } logger.debug("createDataSource() loading underlying JDBC driver."); try { Class.forName(dbDriver); } catch (ClassNotFoundException e) { e.printStackTrace(); } ObjectPool connectionPool = new GenericObjectPool(null); ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(dbUrl, dbUser, dbPass); PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory, connectionPool, null, null, false, true); PoolingDataSource ds = new PoolingDataSource(connectionPool); if (ds == null) { logger.error("createDataSource() could not create data source"); } return ds; }
From source file:Main.java
@SuppressLint("NewApi") @SuppressWarnings("all") private static boolean setProxyKK(WebView webView, String host, int port, String applicationClassName) { Context appContext = webView.getContext().getApplicationContext(); if (null == host) { System.clearProperty("http.proxyHost"); System.clearProperty("http.proxyPort"); System.clearProperty("https.proxyHost"); System.clearProperty("https.proxyPort"); } else {/* ww w . ja va 2 s . co m*/ System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port + ""); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", port + ""); } try { Class applictionCls = Class.forName(applicationClassName); Field loadedApkField = applictionCls.getField("mLoadedApk"); loadedApkField.setAccessible(true); Object loadedApk = loadedApkField.get(appContext); Class loadedApkCls = Class.forName("android.app.LoadedApk"); Field receiversField = loadedApkCls.getDeclaredField("mReceivers"); receiversField.setAccessible(true); Map receivers = (Map) receiversField.get(loadedApk); for (Object receiverMap : receivers.values()) { for (Object rec : ((Map) receiverMap).keySet()) { Class clazz = rec.getClass(); if (clazz.getName().contains("ProxyChangeListener")) { Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class); Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION); /*********** optional, may be need in future *************/ final String CLASS_NAME = "android.net.ProxyProperties"; Class cls = Class.forName(CLASS_NAME); Constructor constructor = cls.getConstructor(String.class, Integer.TYPE, String.class); constructor.setAccessible(true); Object proxyProperties = constructor.newInstance(host, port, null); intent.putExtra("proxy", (Parcelable) proxyProperties); /*********** optional, may be need in future *************/ onReceiveMethod.invoke(rec, appContext, intent); } } } Log.d(LOG_TAG, "Setting proxy with >= 4.4 API successful!"); return true; } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } return false; }
From source file:org.web4thejob.util.L10nUtil.java
public static String getMessage(String className, String code, String defaultValue) { Class clazz;/* w ww .j a v a 2 s. co m*/ try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { e.printStackTrace(); return defaultValue; } return getMessage(clazz, code, null, defaultValue); }
From source file:com.connectsdk.service.config.ServiceConfig.java
@SuppressWarnings("unchecked") public static ServiceConfig getConfig(JSONObject json) { Class<ServiceConfig> newServiceClass; try {/*from w w w . j ava 2 s. co m*/ newServiceClass = (Class<ServiceConfig>) Class .forName(ServiceConfig.class.getPackage().getName() + "." + json.optString(KEY_CLASS)); Constructor<ServiceConfig> constructor = newServiceClass.getConstructor(JSONObject.class); return constructor.newInstance(json); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } return null; }
From source file:com.kbotpro.handlers.ScriptMetaDataManager.java
public static void loadScriptMetaData() { if (System.currentTimeMillis() - lastUpdated > 3600) { // One hour String xml = StaticStorage.serverCom.getScriptList(); try {//from w w w .j a v a 2 s.c o m Document doc = new SAXBuilder().build(new StringReader(xml)); List<ScriptMetaData> loadedScriptMetaData = new ArrayList<ScriptMetaData>(); Element root = doc.getRootElement(); for (Element script : (List<Element>) root.getChildren("script")) { if (script == null) { continue; } List<Permission> permissionExceptions = new ArrayList<Permission>(); final Element policyNode = script.getChild("spolicy"); if (policyNode != null) { for (Element permission : (List<Element>) policyNode.getChildren("permission")) { String className = permission.getAttributeValue("classname"); try { Class klass = ScriptMetaDataManager.class.forName(className); final Constructor constructor = klass .getConstructor(new Class<?>[] { String.class, String.class }); final Permission perm = (Permission) constructor.newInstance( permission.getAttributeValue("name"), permission.getAttributeValue("actions")); permissionExceptions.add(perm); } catch (ClassNotFoundException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (NoSuchMethodException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (InvocationTargetException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (InstantiationException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (IllegalAccessException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } } ScriptMetaData scriptMetaData = new ScriptMetaData( Integer.parseInt(script.getAttributeValue("ID")), script.getAttributeValue("name"), script.getAttributeValue("author"), Integer.parseInt(script.getAttributeValue("downloads")), StringEscapeUtils.unescapeXml(script.getChildText("description")), script.getAttributeValue("category"), script.getAttributeValue("type"), script.getAttributeValue("version"), Integer.parseInt(script.getAttributeValue("rev")), Integer.parseInt(script.getAttributeValue("modifier")), permissionExceptions); loadedScriptMetaData.add(scriptMetaData); } ScriptMetaDataManager.loadedScriptMetaData = loadedScriptMetaData; } catch (JDOMException e) { Logger.getRootLogger().error("Exception: ", e); //To change body of catch statement use File | Settings | File Templates. } catch (IOException e) { Logger.getRootLogger().error("Exception: ", e); //To change body of catch statement use File | Settings | File Templates. } } }
From source file:org.apache.phoenix.hive.util.HiveConnectionUtil.java
/** * Returns the {#link Connection} from Configuration * @param configuration/* w w w.j a va2s. co m*/ * @return * @throws SQLException */ //TODO redundant public static Connection getConnection(final Table tbl) throws SQLException { Preconditions.checkNotNull(tbl); Map<String, String> TblParams = tbl.getParameters(); String quorum = TblParams.get(HiveConfigurationUtil.ZOOKEEPER_QUORUM) != null ? TblParams.get(HiveConfigurationUtil.ZOOKEEPER_QUORUM).trim() : HiveConfigurationUtil.ZOOKEEPER_QUORUM_DEFAULT; String port = TblParams.get(HiveConfigurationUtil.ZOOKEEPER_PORT) != null ? TblParams.get(HiveConfigurationUtil.ZOOKEEPER_PORT).trim() : HiveConfigurationUtil.ZOOKEEPER_PORT_DEFAULT; String znode = TblParams.get(HiveConfigurationUtil.ZOOKEEPER_PARENT) != null ? TblParams.get(HiveConfigurationUtil.ZOOKEEPER_PARENT).trim() : HiveConfigurationUtil.ZOOKEEPER_PARENT_DEFAULT; if (!znode.startsWith("/")) { znode = "/" + znode; } try { Class.forName("org.apache.phoenix.jdbc.PhoenixDriver"); final Connection conn = DriverManager.getConnection((PhoenixRuntime.JDBC_PROTOCOL + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + quorum + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + port + PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR + znode)); String autocommit = TblParams.get(HiveConfigurationUtil.AUTOCOMMIT); if (autocommit != null && autocommit.equalsIgnoreCase("true")) { conn.setAutoCommit(true); } else { conn.setAutoCommit(false); } return conn; } catch (ClassNotFoundException e) { e.printStackTrace(); } return null; }
From source file:org.bdval.modelselection.BMFCalibrationModel.java
public static BMFCalibrationModel load(final String modelName) { try {/*from www . j a va 2 s .co m*/ final Class clazz = Class.forName("org.bdval.modelselection.bmf." + modelName); final BMFCalibrationModel bmf = (BMFCalibrationModel) clazz.newInstance(); return bmf; } catch (ClassNotFoundException e) { System.err.println("Cannot load BMF calibration implementation. Class not found."); e.printStackTrace(); return null; } catch (IllegalAccessException e) { System.err.println("Cannot instantiate BMF calibration implementation."); e.printStackTrace(); } catch (InstantiationException e) { System.err.println("Cannot instantiate BMF calibration implementation."); e.printStackTrace(); } return null; }
From source file:de.static_interface.sinklibrary.util.Debug.java
/** * @return Simple name of the class or {@link #ANONYMOUS_CLASS} if the class is an anonymous class *//*w w w .ja va2s . com*/ @Nonnull @Nullable public static String getCallerClassName() { StackTraceElement[] stElements = Thread.currentThread().getStackTrace(); int index = STACK_INDEX; try { if (stElements[index].getClassName().equalsIgnoreCase("de.static_interface.sinklibrary.Logger")) { index++; // fix for old Logger#debug calls } String className = stElements[index].getClassName(); if (StringUtil.isEmptyOrNull(className)) { return ANONYMOUS_CLASS; } return Class.forName(className).getSimpleName(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return null; }