Example usage for java.lang InstantiationException printStackTrace

List of usage examples for java.lang InstantiationException printStackTrace

Introduction

In this page you can find the example usage for java.lang InstantiationException 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 void main(String[] args) {
    try {//from   ww  w.  j  a  v a  2s.c  om
        String pc = String.class.newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

From source file:Cls.java

public static void main(String... args) {
    try {// ww w  .ja  v  a  2 s  . c  o m
        Class<?> c = Class.forName("Cls");
        c.newInstance(); // InstantiationException

        // production code should handle these exceptions more gracefully
    } catch (InstantiationException x) {
        x.printStackTrace();
    } catch (IllegalAccessException x) {
        x.printStackTrace();
    } catch (ClassNotFoundException x) {
        x.printStackTrace();
    }
}

From source file:Charge.java

public static void main(String... args) {
    try {//  www  . j a v a2  s .c  om
        Class<?> c = Charge.class;

        Constructor[] ctors = c.getDeclaredConstructors();
        for (Constructor ctor : ctors) {
            out.format("Constructor: %s%n", ctor.toGenericString());
            ctor.setAccessible(true);
            ctor.newInstance();
        }

        // production code should handle these exceptions more gracefully
    } catch (InstantiationException x) {
        x.printStackTrace();
    } catch (IllegalAccessException x) {
        x.printStackTrace();
    } catch (InvocationTargetException x) {
        x.printStackTrace();
    }
}

From source file:Main.java

public static void main(String... args) {
    Constructor[] ctors = Console.class.getDeclaredConstructors();
    Constructor ctor = null;/*from   w w w .  ja  v  a2s  . c om*/
    for (int i = 0; i < ctors.length; i++) {
        ctor = ctors[i];
        if (ctor.getGenericParameterTypes().length == 0)
            break;
    }

    try {
        ctor.setAccessible(true);
        Console c = (Console) ctor.newInstance();
        Field f = c.getClass().getDeclaredField("cs");
        f.setAccessible(true);
        out.format("Console charset         :  %s%n", f.get(c));
        out.format("Charset.defaultCharset():  %s%n", Charset.defaultCharset());

        // production code should handle these exceptions more gracefully
    } catch (InstantiationException x) {
        x.printStackTrace();
    } catch (InvocationTargetException x) {
        x.printStackTrace();
    } catch (IllegalAccessException x) {
        x.printStackTrace();
    } catch (NoSuchFieldException x) {
        x.printStackTrace();
    }
}

From source file:EmailAliases.java

public static void main(String... args) {
    try {//  w ww .  j av a  2 s.c  o m
        Constructor ctor = EmailAliases.class.getDeclaredConstructor(HashMap.class);
        ctor.setAccessible(true);
        EmailAliases email = (EmailAliases) ctor.newInstance(defaultAliases);
        email.printKeys();

        // production code should handle these exceptions more gracefully
    } catch (InstantiationException x) {
        x.printStackTrace();
    } catch (IllegalAccessException x) {
        x.printStackTrace();
    } catch (InvocationTargetException x) {
        x.printStackTrace();
    } catch (NoSuchMethodException x) {
        x.printStackTrace();
    }
}

From source file:org.apache.vxquery.xtest.util.DiskPerformance.java

public static void main(String... args) throws IOException {
    // First Argument (XML folder)
    if (args.length < 1) {
        System.err.println("Please provide a directory for the test XML documents.");
        return;/*from w w  w  .  j  a  v a 2  s. c o m*/
    }
    // Second argument (threads)
    int threads = 1;
    if (args.length > 1) {
        threads = Integer.parseInt(args[1]);
    }

    // Third argument (repeat)
    int repeat = 1;
    if (args.length > 2) {
        repeat = Integer.parseInt(args[2]);
    }

    // Fourth argument (buffer size)
    int bufferSize = -1;
    if (args.length > 3) {
        bufferSize = Integer.parseInt(args[3]);
    }

    DiskPerformance dp = new DiskPerformance();
    dp.setDirectory(args[0]);

    ArrayList<Class> tests = new ArrayList<Class>();
    // Parsed Character Streams
    tests.add(ParsedBufferedCharacterStream.class);
    //        tests.add(BufferedParsedCharacterStream.class);
    //        tests.add(ParsedCharacterStream.class);
    // Parsed Byte Streams
    //        tests.add(ParsedBufferedByteStream.class);
    //        tests.add(ParsedByteStream.class);
    // Character Streams
    //        tests.add(BufferedReaderBufferedStream.class);
    //        tests.add(BufferedReaderStream.class);
    //        tests.add(ReaderBufferedStream.class);
    //        tests.add(ReaderStream.class);
    // Byte Streams
    //        tests.add(BufferedStream.class);
    //        tests.add(Stream.class);

    System.out.println("------");
    System.out.println("Started Test Group: " + new Date());
    System.out.println("Thread: " + threads);
    System.out.println("Repeat: " + repeat);
    System.out.println("Buffer: " + bufferSize);
    System.out.println("------");

    for (Class<IDiskTest> testClass : tests) {
        for (int r = 0; r < repeat; ++r) {
            try {
                if (threads > 1) {
                    runThreadTest(testClass, dp, threads, bufferSize);
                } else {
                    IDiskTest test = testClass.newInstance();
                    test.setFile(dp.getNextFile());
                    test.setBufferSize(bufferSize);
                    test.setParser(dp.parser);
                    test.run();
                }
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }

        }
    }

}

From source file:gda.hrpd.data.ExcelReader.java

/**
 * @param args//from w ww . j  a  v a2 s  .c  o  m
 */
public static void main(String[] args) {
    System.out.println("testing Excel file reading....");
    ExcelReader er;
    try {
        er = new ExcelReader();
        MultiValueMap sampleData = er.getMvm();
        for (int i = 0; i < sampleData.size(); i++) {
            Collection<?> list = sampleData.getCollection(i);
            for (Object o : list) {
                System.out.print(o + "\t");
            }
            System.out.println();
        }
        // for (Object o : sampleData.keySet()) {
        // System.out.println(sampleData.size(o));
        // Collection sample = sampleData.getCollection(o);
        // System.out.println(sample.size());
        // for (Iterator it=sample.iterator(); it.hasNext();) {
        // Object element = it.next();
        // System.out.print(element.toString() + "\t");
        // }
        // System.out.println();
        // }
    } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:Main.java

public static <T> T newInstanceSafely(Class<T> clz) {
    try {//from   w  w  w .  j a  v a2  s .c o  m
        return clz.newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static <T> T getT(Object o, int i) {
    try {/*from www.ja  v a 2s .com*/
        return ((Class<T>) ((ParameterizedType) (o.getClass().getGenericSuperclass()))
                .getActualTypeArguments()[i]).newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (ClassCastException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Object loadClass(Context context, String path) {
    try {/*from  w w  w.  j a  va 2s. c o m*/
        String dexPath = context.getApplicationInfo().sourceDir;
        PathClassLoader pathClassLoader = new PathClassLoader(dexPath, context.getClassLoader());
        Class<?> c = Class.forName(path, true, pathClassLoader);
        Object ret = c.newInstance();
        return ret;
    } catch (InstantiationException ex1) {
        ex1.printStackTrace();
    } catch (IllegalAccessException ex2) {
        ex2.printStackTrace();
    } catch (ClassNotFoundException ex3) {
        ex3.printStackTrace();
    }

    return null;
}