Example usage for java.lang ClassNotFoundException printStackTrace

List of usage examples for java.lang ClassNotFoundException printStackTrace

Introduction

In this page you can find the example usage for java.lang ClassNotFoundException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

public static boolean doesClassExist(String name) {
    try {//from  w w  w . j ava  2s. c  o m
        Class<?> c = Class.forName(name);
        if (c != null)
            return true;
    } catch (ClassNotFoundException e) {
        // Class not found
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

public static boolean doesClassExist(String name) {
    try {//from w  w w  .j a  v  a2  s . co m
        Class c = Class.forName(name);
        if (c != null)
            return true;
    } catch (ClassNotFoundException e) {
        // Class not found
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

public static Object xmlTobean(String path, String classPath) {
    Object obj = null;//  ww w.j a v  a2 s . c om
    Class<?> obClass = null;
    try {
        obClass = Class.forName(classPath);
    } catch (ClassNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    try {
        File file = new File(path);
        JAXBContext context = JAXBContext.newInstance(obClass);
        Unmarshaller unmarshaller = context.createUnmarshaller();
        obj = unmarshaller.unmarshal(file);
        System.out.println(obj);
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    return obj;
}

From source file:Main.java

public static int getApiLevel() {

    try {//from   w w w . j a v a  2 s.c om
        Class<?> mClassType = Class.forName("android.os.SystemProperties");
        Method mGetIntMethod = mClassType.getDeclaredMethod("getInt", String.class, int.class);
        mGetIntMethod.setAccessible(true);
        return (Integer) mGetIntMethod.invoke(null, "ro.build.version.sdk", 14);
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return 14;

}

From source file:Main.java

private static void loadProviderIfNecessary(String providerClassName) {
    if (providerClassName == null) {
        return;/* w  w w .  j av a2 s  .  c o m*/
    }

    final Class<?> klass;
    try {
        final ClassLoader sysLoader = ClassLoader.getSystemClassLoader();
        if (sysLoader != null) {
            klass = sysLoader.loadClass(providerClassName);
        } else {
            klass = Class.forName(providerClassName);
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        System.exit(1);
        return;
    }

    Constructor<?> constructor = null;
    for (Constructor<?> c : klass.getConstructors()) {
        if (c.getParameterTypes().length == 0) {
            constructor = c;
            break;
        }
    }
    if (constructor == null) {
        System.err.println("No zero-arg constructor found for " + providerClassName);
        System.exit(1);
        return;
    }

    final Object o;
    try {
        o = constructor.newInstance();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
        return;
    }
    if (!(o instanceof Provider)) {
        System.err.println("Not a Provider class: " + providerClassName);
        System.exit(1);
    }

    Security.insertProviderAt((Provider) o, 1);
}

From source file:Main.java

public static void setLookAndFeel(String lafName, JFrame frame) {
    try {//from   w w  w . j  a v  a  2 s  . c  o m
        UIManager.setLookAndFeel(lafName);
        if (frame != null) {
            SwingUtilities.updateComponentTreeUI(frame);
            frame.pack();
        }
    } catch (ClassNotFoundException e) {
        System.err.println("Could not find Look and Feel class!");
        e.printStackTrace();
    } catch (InstantiationException e) {
        System.err.println("Could not instantiate Look and Feel class!");
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        System.err.println("Could not access Look and Feel class!");
        e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
        System.err.println("This Look and Feel is not supported!");
        e.printStackTrace();
    }
}

From source file:org.apache.hadoop.hive.serde2.protobuf.ProtobufUtils.java

public static Class<?> loadFieldMsgClass(Descriptor msgDescriptor) {
    try {//from w  w w  .j  a va2s. com
        String fullName = getFieldMsgFullName(msgDescriptor);
        Class<?> cls = Class.forName(fullName, true, JavaUtils.getClassLoader());
        return cls;
    } catch (java.lang.ClassNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.owasp.webgoat.session.DatabaseUtilities.java

private static Connection makeConnection(String user, WebgoatContext context) throws SQLException {
    try {/* w  w  w . j  a v  a 2s .  c o m*/
        Class.forName(context.getDatabaseDriver());

        if (context.getDatabaseConnectionString().contains("hsqldb"))
            return getHsqldbConnection(user, context);

        String userPrefix = context.getDatabaseUser();
        String password = context.getDatabasePassword();
        String url = context.getDatabaseConnectionString();
        return DriverManager.getConnection(url, userPrefix + "_" + user, password);
    } catch (ClassNotFoundException cnfe) {
        cnfe.printStackTrace();
        throw new SQLException("Couldn't load the database driver: " + cnfe.getLocalizedMessage());
    }
}

From source file:th.ac.kmutt.chart.rest.application.Main.java

private static void systemConfig(SystemM param) {
    SystemM sys = param;//from  ww  w  .  ja va2 s . c  om
    String url = "system";
    HttpPost httppost = new HttpPost("http://localhost:8081/ChartServices/rest/" + url);
    XStream xstream = new XStream(new Dom4JDriver());
    Class c = null;
    try {
        c = Class.forName(sys.getClass().getName());
    } catch (ClassNotFoundException e2) {
        e2.printStackTrace();
    }
    xstream.processAnnotations(c);

    ByteArrayEntity entity = null;

    String xString = xstream.toXML(sys);
    try {
        entity = new ByteArrayEntity(xString.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
    }

    httppost.setEntity(entity);

    CloseableHttpClient httpclient = HttpClientBuilder.create().build();
    HttpResponse response = null;
    HttpEntity resEntity = null;
    try {
        response = httpclient.execute(httppost);
        resEntity = response.getEntity();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    //httpclient.getConnectionManager().shutdown();
    try {
        httpclient.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.shadwelldacunha.byteswipe.core.Utilities.java

public static void setLookAndFeel() {
    //TODO: Handle exceptions gracefully
    try {//ww w .ja v  a2  s .c o  m
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
        e.printStackTrace();
    }
}