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(PrintStream s) 

Source Link

Document

Prints this throwable and its backtrace to the specified print stream.

Usage

From source file:Logging.java

public static void main(String args[]) throws Exception {
    FileOutputStream errors = new FileOutputStream("StdErr.txt", true);
    PrintStream stderr = new PrintStream(errors);
    PrintWriter errLog = new PrintWriter(errors, true);
    System.setErr(stderr);/*from  ww w  . j av  a 2 s.  co m*/

    String query = "SELECT Name,Description,Qty,Cost,Sell_Price FROM Stock";

    try {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        Connection con = DriverManager.getConnection("jdbc:odbc:Inventory");
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(query);
        while (rs.next()) {
            String name = rs.getString("Name");
            String desc = rs.getString("Description");
            int qty = rs.getInt("Qty");
            float cost = rs.getFloat("Cost");
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace(errLog);
    } catch (SQLException e) {
        System.err.println((new GregorianCalendar()).getTime());
        System.err.println("Thread: " + Thread.currentThread());
        System.err.println("ErrorCode: " + e.getErrorCode());
        System.err.println("SQLState:  " + e.getSQLState());
        System.err.println("Message:   " + e.getMessage());
        System.err.println("NextException: " + e.getNextException());
        e.printStackTrace(errLog);
        System.err.println();
    }
    stderr.close();
}

From source file:ca.nines.ise.Main.java

/**
 * Entry point for the application. Catches all exceptions.
 *
 * @param args command line arguments.//w  w  w .  java  2 s. c o  m
 */
public static void main(String[] args) {
    String version = "unknown";
    try {
        if (args.length == 0) {
            args = new String[] { "help" };
        }
        version = version();
        execute(args);
    } catch (ClassNotFoundException ex) {
        System.err.println("Cannot find command class " + args[0]);
        System.err.println("iTools version " + version);
        ex.printStackTrace(System.err);
    } catch (IllegalAccessException ex) {
        System.err.println("Cannot access command class " + args[0]);
        System.err.println("iTools version " + version);
        ex.printStackTrace(System.err);
    } catch (InstantiationException ex) {
        System.err.println("Cannot create command class " + args[0]);
        System.err.println("iTools version " + version);
        ex.printStackTrace(System.err);
    } catch (ParseException ex) {
        System.err.println("Cannot parse command line arguments " + args[0]);
        System.err.println(ex.getMessage());
        System.err.println("iTools version " + version);
        ex.printStackTrace(System.err);
    } catch (IOException ex) {
        System.err.println("I/O error " + args[0]);
        System.err.println("iTools version " + version);
        ex.printStackTrace(System.err);
    } catch (Exception ex) {
        System.err.println("Internal error " + args[0]);
        System.err.println("iTools version " + version);
        ex.printStackTrace(System.err);
    }
}

From source file:org.apache.flink.client.FlinkYarnSessionCli.java

public static AbstractFlinkYarnClient getFlinkYarnClient() {
    AbstractFlinkYarnClient yarnClient;//w ww. j av a2s.c o  m
    try {
        Class<? extends AbstractFlinkYarnClient> yarnClientClass = Class
                .forName("org.apache.flink.yarn.FlinkYarnClient").asSubclass(AbstractFlinkYarnClient.class);
        yarnClient = InstantiationUtil.instantiate(yarnClientClass, AbstractFlinkYarnClient.class);
    } catch (ClassNotFoundException e) {
        System.err.println("Unable to locate the Flink YARN Client. "
                + "Please ensure that you are using a Flink build with Hadoop2/YARN support. Message: "
                + e.getMessage());
        e.printStackTrace(System.err);
        return null; // make it obvious
    }
    return yarnClient;
}

From source file:info.guardianproject.netcipher.web.WebkitProxy.java

@TargetApi(19)
private static boolean setKitKatProxy(String appClass, Context appContext, String host, int port) {
    //Context appContext = webView.getContext().getApplicationContext();

    if (host != null) {
        System.setProperty("http.proxyHost", host);
        System.setProperty("http.proxyPort", port + "");
        System.setProperty("https.proxyHost", host);
        System.setProperty("https.proxyPort", port + "");
    }//w w  w  .  j  a v  a2 s. c  o m

    try {
        Class applictionCls = Class.forName(appClass);
        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);
        ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object rec : ((ArrayMap) 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);

                    if (host != null) {
                        /*********** 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);
                }
            }
        }
        return true;
    } catch (ClassNotFoundException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    } catch (NoSuchFieldException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    } catch (IllegalAccessException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    } catch (IllegalArgumentException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    } catch (NoSuchMethodException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    } catch (InvocationTargetException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    } catch (InstantiationException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    }
    return false;
}

From source file:info.guardianproject.netcipher.webkit.WebkitProxy.java

@TargetApi(19)
private static boolean setKitKatProxy(String appClass, Context appContext, String host, int port) {
    //Context appContext = webView.getContext().getApplicationContext();

    if (host != null) {
        System.setProperty("http.proxyHost", host);
        System.setProperty("http.proxyPort", Integer.toString(port));
        System.setProperty("https.proxyHost", host);
        System.setProperty("https.proxyPort", Integer.toString(port));
    }/* w  w w .j a v a  2s  .  c o  m*/

    try {
        Class applictionCls = Class.forName(appClass);
        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);
        ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk);
        for (Object receiverMap : receivers.values()) {
            for (Object rec : ((ArrayMap) 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);

                    if (host != null) {
                        /*********** 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);
                }
            }
        }
        return true;
    } catch (ClassNotFoundException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    } catch (NoSuchFieldException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    } catch (IllegalAccessException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    } catch (IllegalArgumentException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    } catch (NoSuchMethodException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    } catch (InvocationTargetException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    } catch (InstantiationException e) {
        StringWriter sw = new StringWriter();
        e.printStackTrace(new PrintWriter(sw));
        String exceptionAsString = sw.toString();
        Log.v(TAG, e.getMessage());
        Log.v(TAG, exceptionAsString);
    }
    return false;
}

From source file:at.univie.sensorium.SensorService.java

private void startSensors() {
    Resources res = getResources();
    String[] sensorclassnames = res.getStringArray(R.array.sensors);

    for (String classname : sensorclassnames) {
        Log.d("SENSORS", classname);
        try {/*from  w w  w  .ja  v a  2s.  com*/
            AbstractSensor s = (AbstractSensor) Class.forName(classname).newInstance();
            SensorRegistry.getInstance().registerSensor(s);
        } catch (ClassNotFoundException e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            Log.d(SensorRegistry.TAG, sw.toString());
        } catch (InstantiationException e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            Log.d(SensorRegistry.TAG, sw.toString());
        } catch (IllegalAccessException e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            Log.d(SensorRegistry.TAG, sw.toString());
        }
    }
}

From source file:net.mypapit.mobile.myrepeater.RepeaterHistoryActivity.java

@SuppressWarnings("unchecked")
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    setContentView(R.layout.repeater_list);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }/*from   w w w.ja va 2 s . c  o m*/

    Intent intent = this.getIntent();
    ArrayList<Repeater> al = (ArrayList<Repeater>) intent.getExtras().get("historylist");

    double lat = intent.getExtras().getDouble("lat");
    double lon = intent.getExtras().getDouble("lon");

    if (al == null) {
        al = new ArrayList<Repeater>();
        Log.d("net.mypapit.mobile", "null Array List");
    }

    // RepeaterList rl = new RepeaterList();

    try {
        File infile = new File(Environment.getExternalStorageDirectory(), "history.txt");
        FileInputStream fis = new FileInputStream(infile);

        ObjectInputStream ois = new ObjectInputStream(fis);

        stackhistory = (StackHistory) ois.readObject();
        ois.close();
    } catch (IOException ioex) {
        stackhistory = new StackHistory();
        Log.d("net.mypapit.mobile", ioex.getMessage());
        ioex.printStackTrace(System.err);

    } catch (ClassNotFoundException cnfe) {
        stackhistory = new StackHistory();
        Log.d("net.mypapit.mobile", cnfe.getMessage());
        cnfe.printStackTrace(System.err);
    }
    RepeaterList rl = new RepeaterList(stackhistory);
    // rl.add(new Repeater("sux", "sux", "sux", "sux", "sux", 0, 0, 0, 0,
    // 0));
    Repeater repeater = new Repeater("unknown", lat, lon);
    repeater.calcDistanceAll(rl);
    // rl.sort();

    lv = (ListView) findViewById(R.id.repeaterListView);
    tvAddress = (TextView) findViewById(R.id.tvAddress);
    tvAddress.setText("Recently searched repeater");

    adapter = new RepeaterAdapter(this, rl, 100, false);

    lv.setAdapter(adapter);

}

From source file:TaskManager.java

public Connection buildConnection() {
    try {//from   w  ww  .  j  a  v  a  2 s . com
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException cnfX) {
        cnfX.printStackTrace(System.err);
        return (null);
    }

    try {
        Connection conn = DriverManager.getConnection(getUrl(), getUsername(), getPassword());

        return (conn);
    } catch (SQLException sqlX) {
        System.out.println(SqlExceptionReader.readException(sqlX));
        return (null);
    }
}

From source file:morphy.command.SetCommand.java

/** Uses reflection  */
private StyleInterface getStyle(int styleNum) {
    try {/*w w  w. j a v  a  2 s  .  c o  m*/
        Class<?> myClass = Class.forName("morphy.game.style.Style" + styleNum);
        return (StyleInterface) myClass.getMethod("getSingletonInstance").invoke(null);
    } catch (ClassNotFoundException e) {
        e.printStackTrace(System.err);
    } catch (IllegalAccessException e) {
        e.printStackTrace(System.err);
    } catch (IllegalArgumentException e) {
        e.printStackTrace(System.err);
    } catch (SecurityException e) {
        e.printStackTrace(System.err);
    } catch (InvocationTargetException e) {
        e.printStackTrace(System.err);
    } catch (NoSuchMethodException e) {
        e.printStackTrace(System.err);
    }
    return null;
}