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:AWTUtilities.java

/**
 * Returns a list of available font names. Under JDK1.1 it uses
 * <code>Toolkit.getFontList()</code> while under JDK1.2 (via reflection),
 * <code>GraphicsEnvironment.getAvailableFontFamilyNames()</code>
 *//*from w w  w . j  ava 2 s  .  c  om*/

public static String[] getAvailableFontNames() {
    if (PlatformUtils.isJavaBetterThan("1.2")) {
        try {
            // The equivalent of "return GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();"
            Class geClass = Class.forName("java.awt.GraphicsEnvironment");
            Method getLocalGraphicsEnvironmentMethod = geClass.getMethod("getLocalGraphicsEnvironment",
                    new Class[0]);
            Object localGE = getLocalGraphicsEnvironmentMethod.invoke(null, new Object[0]);
            Method getAvailableFontFamilyNamesMethod = geClass.getMethod("getAvailableFontFamilyNames",
                    new Class[0]);
            String[] fontNames = (String[]) getAvailableFontFamilyNamesMethod.invoke(localGE, new Object[0]);
            return fontNames;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return null;
    } else
        return Toolkit.getDefaultToolkit().getFontList();
}

From source file:com.swordlord.gozer.builder.Parser.java

/**
  * Retrieve the package name/*  w ww  .  ja  v a2 s.  c  om*/
  * 
  * @param basepkgname
  * @return
  */
public static List<String> getPackageNames(String basepkgname) {
    ArrayList<String> packages = new ArrayList<String>();
    try {
        File directory = getClassesHelper(basepkgname);
        if (directory.isDirectory() && directory.exists()) {
            for (File f : directory.listFiles()) {
                if (f.isDirectory()) {
                    packages.add(basepkgname + "." + f.getName());
                }
            }
        }
        return packages;
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.apache.jorphan.test.AllTests.java

/**
 * An overridable method that that instantiates a UnitTestManager (if one
 * was specified in the command-line arguments), and hands it the name of
 * the properties file to use to configure the system.
 * /*w  w  w. java  2s  .  co m*/
 * @param args
 */
protected static void initializeManager(String[] args) {
    if (args.length >= 3) {
        try {
            System.out.println("Using initializeProperties() from " + args[2]);
            UnitTestManager um = (UnitTestManager) Class.forName(args[2]).newInstance();
            System.out.println("Setting up initial properties using: " + args[1]);
            um.initializeProperties(args[1]);
        } catch (ClassNotFoundException e) {
            System.out.println("Couldn't create: " + args[2]);
            e.printStackTrace();
        } catch (InstantiationException e) {
            System.out.println("Couldn't create: " + args[2]);
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            System.out.println("Couldn't create: " + args[2]);
            e.printStackTrace();
        }
    }
}

From source file:AWTUtilities.java

/**
 * Attempts to determine the usable screen bounds of the default screen
 * device. If the require java.awt API is not available under the JVM we're
 * running in, this will simply return the screen bounds obtained via
 * <code>Toolkit.getScreenSize()</code>.
 *//* w  w  w .j  a  v  a 2s.c  om*/

public static Rectangle getUsableScreenBounds() {
    if (PlatformUtils.isJavaBetterThan("1.4")) {
        try {
            Class graphicsEnvironmentClass = Class.forName("java.awt.GraphicsEnvironment");
            Class graphicsDeviceClass = Class.forName("java.awt.GraphicsDevice");
            Class graphicsConfigurationClass = Class.forName("java.awt.GraphicsConfiguration");

            Class[] emptyClassArr = new Class[0];
            Method getLocalGraphicsEnvironmentMethod = graphicsEnvironmentClass
                    .getMethod("getLocalGraphicsEnvironment", emptyClassArr);
            Method getDefaultScreenDeviceMethod = graphicsEnvironmentClass.getMethod("getDefaultScreenDevice",
                    emptyClassArr);
            Method getDefaultConfigurationMethod = graphicsDeviceClass.getMethod("getDefaultConfiguration",
                    emptyClassArr);
            Method getBoundsMethod = graphicsConfigurationClass.getMethod("getBounds", emptyClassArr);
            Method getScreenInsetsMethod = Toolkit.class.getMethod("getScreenInsets",
                    new Class[] { graphicsConfigurationClass });

            Object[] emptyObjArr = new Object[0];
            Object graphicsEnvironment = getLocalGraphicsEnvironmentMethod.invoke(null, emptyObjArr);
            Object defaultScreenDevice = getDefaultScreenDeviceMethod.invoke(graphicsEnvironment, emptyObjArr);
            Object defaultConfiguration = getDefaultConfigurationMethod.invoke(defaultScreenDevice,
                    emptyObjArr);
            Rectangle bounds = (Rectangle) getBoundsMethod.invoke(defaultConfiguration, emptyObjArr);
            Insets insets = (Insets) getScreenInsetsMethod.invoke(Toolkit.getDefaultToolkit(),
                    new Object[] { defaultConfiguration });

            bounds.x += insets.left;
            bounds.y += insets.top;
            bounds.width -= insets.left + insets.right;
            bounds.height -= insets.top + insets.bottom;

            return bounds;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    return new Rectangle(new Point(0, 0), Toolkit.getDefaultToolkit().getScreenSize());
}

From source file:com.swordlord.gozer.builder.Parser.java

/**
 * Retrieve a Class//ww w .  j  a  va  2 s .co m
 * 
 * @param pckgname
 * @param skipDollarClasses
 * @return the class
 */
public static Class<?>[] getClasses(String pckgname, boolean skipDollarClasses) {
    ArrayList<Class<?>> classes = new ArrayList<Class<?>>();

    try {
        File directory = getClassesHelper(pckgname);

        if (directory.exists()) {
            // Get the list of the files contained in the package
            String[] files = directory.list();
            for (int i = 0; i < files.length; i++) {
                // we are only interested in .class files
                if (files[i].endsWith(".class")) {
                    // get rid of the ".class" at the end
                    String withoutclass = pckgname + '.' + files[i].substring(0, files[i].length() - 6);

                    // in case we don't want $1 $2 etc. endings (i.e. common
                    // in GUI classes)
                    if (skipDollarClasses) {
                        int dollar_occurence = withoutclass.indexOf("$");
                        if (dollar_occurence != -1) {
                            withoutclass = withoutclass.substring(0, dollar_occurence);
                        }
                    }

                    // add this class to our list but avoid duplicates
                    boolean already_contained = false;
                    for (Class<?> c : classes) {
                        if (c.getCanonicalName().equals(withoutclass)) {
                            already_contained = true;
                        }
                    }
                    if (!already_contained) {
                        classes.add(Class.forName(withoutclass));
                    }
                    // REMARK this kind of checking is quite slow using
                    // reflection, it would be better
                    // to do the class.forName(...) stuff outside of this
                    // method and change the method
                    // to only return an ArrayList with fqcn Strings. Also
                    // in reality we have the $1 $2
                    // etc. classes in our packages, so we are skipping some
                    // "real" classes here
                }
            }
        } else {
            throw new ClassNotFoundException(pckgname + " does not appear to be a valid package");
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    Class<?>[] classesA = new Class[classes.size()];
    classes.toArray(classesA);
    return classesA;
}

From source file:org.apache.cordova.X5CoreAndroid.java

public static Object getBuildConfigValue(Context ctx, String key) {
    try {// www  .j av a2 s  . co  m
        Class<?> clazz = Class.forName(ctx.getPackageName() + ".BuildConfig");
        Field field = clazz.getField(key);
        return field.get(null);
    } catch (ClassNotFoundException e) {
        LOG.d(TAG, "Unable to get the BuildConfig, is this built with ANT?");
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        LOG.d(TAG, key + " is not a valid field. Check your build.gradle");
    } catch (IllegalAccessException e) {
        LOG.d(TAG, "Illegal Access Exception: Let's print a stack trace.");
        e.printStackTrace();
    }

    return null;
}

From source file:com.ery.hadoop.mrddx.hive.HiveOutputFormat.java

/**
 * ddlHQL?/* ww  w. j av a2  s.  co  m*/
 * 
 * @param hiveConf hive?
 * @throws SQLException
 */
public static void executeDDLHQL(HiveConfiguration hiveConf, String ddl) throws SQLException {
    if (null == ddl || ddl.trim().length() <= 0) {
        return;
    }
    Connection conn = null;
    try {
        conn = hiveConf.getOutputConnection();
    } catch (ClassNotFoundException e) {
        MRLog.error(LOG, "create hive conn error!");
        e.printStackTrace();
    }

    Statement stat = conn.createStatement();
    try {
        stat.execute(ddl);
    } catch (Exception e) {
        MRLog.errorException(LOG, "execute ddl error, hql:" + ddl, e);
    }

    // 
    close(conn);
}

From source file:com.ery.hadoop.mrddx.hive.HiveOutputFormat.java

/**
 * ddlHQL?//from   w w  w. j a  v a 2s  .c  om
 * 
 * @param hiveConf hive?
 * @throws SQLException
 */
public static void executeDDLHQL(HiveConfiguration hiveConf) throws SQLException {
    String ddls = hiveConf.getOutputHiveExecuteDDLHQL();
    if (null == ddls || ddls.trim().length() <= 0) {
        return;
    }
    String ddl[] = ddls.split(";");
    Connection conn = null;
    try {
        conn = hiveConf.getOutputConnection();
    } catch (ClassNotFoundException e) {
        MRLog.error(LOG, "create hive conn error!");
        e.printStackTrace();
    }

    Statement stat = conn.createStatement();
    for (int i = 0; i < ddl.length; i++) {
        try {
            stat.executeQuery(ddl[i]);
        } catch (Exception e) {
            MRLog.errorException(LOG, "execute ddl error, hql:" + ddl[i], e);
        }
    }

    // 
    close(conn);
}

From source file:edu.umass.cs.reconfiguration.reconfigurationpackets.ReconfigurationPacket.java

private static BasicReconfigurationPacket<?> getReconfigurationPacket(JSONObject json,
        Map<ReconfigurationPacket.PacketType, Class<?>> typeMap, Stringifiable<?> unstringer,
        boolean forcePrintException) throws JSONException {
    BasicReconfigurationPacket<?> rcPacket = null;
    ReconfigurationPacket.PacketType rcType = null;
    String canonicalClassName = null;
    try {//from w  w  w. ja v a2s . c o m
        long t = System.nanoTime();
        if ((rcType = ReconfigurationPacket.PacketType.intToType.get(JSONPacket.getPacketType(json))) != null
                && (canonicalClassName = getPacketTypeCanonicalClassName(rcType)) != null) {
            rcPacket = (BasicReconfigurationPacket<?>) (Class.forName(canonicalClassName)
                    .getConstructor(JSONObject.class, Stringifiable.class).newInstance(json, unstringer));
        }
        DelayProfiler.updateDelayNano("rc_reflection", t);
    } catch (NoSuchMethodException nsme) {
        nsme.printStackTrace();
    } catch (InvocationTargetException ite) {
        ite.printStackTrace();
    } catch (IllegalAccessException iae) {
        iae.printStackTrace();
    } catch (ClassNotFoundException cnfe) {
        Reconfigurator.getLogger().info("Class " + canonicalClassName + " not found");
        cnfe.printStackTrace();
    } catch (InstantiationException ie) {
        ie.printStackTrace();
    } finally {
        if (forcePrintException
                && ReconfigurationPacket.PacketType.intToType.get(JSONPacket.getPacketType(json)) == null) {
            (new RuntimeException("No reconfiguration packet type found in: " + json)).printStackTrace();
        }
    }

    return rcPacket;
}

From source file:com.airbop.library.simple.AirBopGCMIntentService.java

/**
 * Issues a notification to inform the user that server has sent a message.
 *//* www. j  a v a2s .  c  o  m*/
private static void generateNotification(Context context, String title, String message) {

    AirBopManifestSettings airBop_settings = CommonUtilities.loadDataFromManifest(context);
    //int icon = R.drawable.ic_stat_gcm;
    int icon = 0;
    Resources res = context.getResources();
    if (res != null) {
        //icon = res.getIdentifier(airBop_settings.mDefaultNotificationIcon, null, null);
        icon = airBop_settings.mNotificationIcon;
    }
    long when = System.currentTimeMillis();
    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    //if ((title == null) || (title.equals(""))) {
    if (title == null) {
        title = airBop_settings.mDefaultNotificationTitle;
    }
    Class intent_class = null;
    if (context != null) {
        ClassLoader class_loader = context.getClassLoader();
        if (class_loader != null) {
            try {
                if (airBop_settings.mDefaultNotificationClass != null) {
                    intent_class = Class.forName(airBop_settings.mDefaultNotificationClass);
                }
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //Log.i(TAG, "intent_class: " + intent_class);
        }
    }
    Intent notificationIntent = null;
    if (intent_class != null) {
        notificationIntent = new Intent(context, intent_class);
    } else {
        notificationIntent = new Intent(Intent.ACTION_VIEW);
    }
    // set intent so it does not start a new activity
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent intent = PendingIntent.getActivity(context, 0, notificationIntent, 0);

    Notification notification = new NotificationCompat.Builder(context).setContentTitle(title)
            .setContentText(message).setContentIntent(intent).setSmallIcon(icon).setWhen(when)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(message)).build();

    notification.flags |= Notification.FLAG_AUTO_CANCEL;
    notificationManager.notify(0, notification);
}