List of usage examples for java.lang ClassNotFoundException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void main(String[] args) { try {//from ww w . j av a2 s . c o m DataFlavor df1 = new DataFlavor("text/plain; charset=ASCII"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Main.java
public static void main(String... args) { String argType = (args.length == 0 ? "" : args[0]); try {// ww w. ja v a 2s . co m Class<?> c = Class.forName("Main"); if ("".equals(argType)) { // IllegalArgumentException: wrong number of arguments Object o = c.getConstructor().newInstance("foo"); } else if ("int".equals(argType)) { // NoSuchMethodException - looking for int, have Integer Object o = c.getConstructor(int.class); } else if ("Object".equals(argType)) { // newInstance() does not perform method resolution Object o = c.getConstructor(Object.class).newInstance("foo"); } else { assert false; } // production code should handle these exceptions more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } catch (NoSuchMethodException x) { x.printStackTrace(); } catch (InvocationTargetException x) { x.printStackTrace(); } catch (InstantiationException x) { x.printStackTrace(); } catch (IllegalAccessException x) { x.printStackTrace(); } }
From source file:InheritedMethods.java
public static void main(String... args) { try {// w w w .j ava2 s. com Class<?> c = Class.forName(args[0]); printMethods(c); Class parent = c.getSuperclass(); while (parent != null) { printMethods(parent); parent = parent.getSuperclass(); } // production code should handle this exception more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:org.openiot.gsn.http.rest.RemoteWrapperHttpClient.java
public static void main(String[] args) throws ClientProtocolException, IOException, ClassNotFoundException { DefaultHttpClient httpclient = new DefaultHttpClient(); final String url = "select * from localsystemtime where timed > 10/10"; HttpGet httpget = new HttpGet( "http://localhost:22001/streaming/" + URLEncoder.encode(url, "UTF-8") + "/12345"); HttpResponse response = httpclient.execute(httpget); ObjectInputStream out = (StreamElement4Rest.getXstream()) .createObjectInputStream((response.getEntity().getContent())); DataField[] structure = (DataField[]) out.readObject(); StreamElement4Rest se = null;/*w w w.j ava 2 s. com*/ try { while ((se = (StreamElement4Rest) out.readObject()) != null) { System.out.println(se.toStreamElement()); } } catch (ClassNotFoundException e) { e.printStackTrace(); } }
From source file:ArrayFind.java
public static void main(String... args) { boolean found = false; try {/* w w w .j ava2 s . c o m*/ Class<?> cls = Class.forName(args[0]); Field[] flds = cls.getDeclaredFields(); for (Field f : flds) { Class<?> c = f.getType(); if (c.isArray()) { found = true; out.format( "%s%n" + " Field: %s%n" + " Type: %s%n" + " Component Type: %s%n", f, f.getName(), c, c.getComponentType()); } } if (!found) { out.format("No array fields%n"); } // production code should handle this exception more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:MethodSpy.java
public static void main(String... args) { try {// w w w . ja va2 s . co m Class<?> c = Class.forName(args[0]); Method[] allMethods = c.getDeclaredMethods(); for (Method m : allMethods) { if (!m.getName().equals(args[1])) { continue; } out.format("%s%n", m.toGenericString()); out.format(fmt, "ReturnType", m.getReturnType()); out.format(fmt, "GenericReturnType", m.getGenericReturnType()); } // production code should handle these exceptions more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:JavaDBDemo.java
public static void main(String[] args) { String driver = "org.apache.derby.jdbc.EmbeddedDriver"; String connectionURL = "jdbc:derby:myDatabase;create=true"; String createString = "CREATE TABLE Employee (NAME VARCHAR(32) NOT NULL, ADDRESS VARCHAR(50) NOT NULL)"; try {//from ww w. j a va 2s . c o m Class.forName(driver); } catch (java.lang.ClassNotFoundException e) { e.printStackTrace(); } try { conn = DriverManager.getConnection(connectionURL); Statement stmt = conn.createStatement(); stmt.executeUpdate(createString); PreparedStatement psInsert = conn.prepareStatement("insert into Employee values (?,?)"); psInsert.setString(1, args[0]); psInsert.setString(2, args[1]); psInsert.executeUpdate(); Statement stmt2 = conn.createStatement(); ResultSet rs = stmt2.executeQuery("select * from Employee"); int num = 0; while (rs.next()) { System.out.println(++num + ": Name: " + rs.getString(1) + "\n Address" + rs.getString(2)); } rs.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:ConstructorTroubleToo.java
public static void main(String... args) { try {/*from w w w .j ava 2 s . c om*/ Class<?> c = Class.forName("ConstructorTroubleToo"); // Method propagetes any exception thrown by the constructor (including checked exceptions). if (args.length > 0 && args[0].equals("class")) { Object o = c.newInstance(); } else { Object o = c.getConstructor().newInstance(); } // production code should handle these exceptions more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } catch (InstantiationException x) { x.printStackTrace(); } catch (IllegalAccessException x) { x.printStackTrace(); } catch (NoSuchMethodException x) { x.printStackTrace(); } catch (InvocationTargetException x) { x.printStackTrace(); err.format("%n%nCaught exception: %s%n", x.getCause()); } }
From source file:ConstructorAccess.java
public static void main(String... args) { try {/* w w w . j a v a2 s. c om*/ Class<?> c = Class.forName(args[0]); Constructor[] allConstructors = c.getDeclaredConstructors(); for (Constructor ctor : allConstructors) { int searchMod = modifierFromString(args[1]); int mods = accessModifiers(ctor.getModifiers()); if (searchMod == mods) { out.format("%s%n", ctor.toGenericString()); out.format(" [ synthetic=%-5b var_args=%-5b ]%n", ctor.isSynthetic(), ctor.isVarArgs()); } } // production code should handle this exception more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } }
From source file:ConstructorSift.java
public static void main(String... args) { try {//from ww w .ja v a 2 s. com Class<?> cArg = Class.forName(args[1]); Class<?> c = Class.forName(args[0]); Constructor[] allConstructors = c.getDeclaredConstructors(); for (Constructor ctor : allConstructors) { Class<?>[] pType = ctor.getParameterTypes(); for (int i = 0; i < pType.length; i++) { if (pType[i].equals(cArg)) { out.format("%s%n", ctor.toGenericString()); Type[] gpType = ctor.getGenericParameterTypes(); for (int j = 0; j < gpType.length; j++) { char ch = (pType[j].equals(cArg) ? '*' : ' '); out.format("%7c%s[%d]: %s%n", ch, "GenericParameterType", j, gpType[j]); } break; } } } // production code should handle this exception more gracefully } catch (ClassNotFoundException x) { x.printStackTrace(); } }