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:org.cobaltians.cobalt.font.CobaltFontManager.java

/**
 * Initializes and returns a font drawable with a font icon identifier, color, text size and padding
 * @param context the activity context//from  w  w w.  j a v  a 2 s.c  o  m
 * @param identifier the font icon identifier as "font-key font-icon" (i.e.: fa fa-mobile)
 * @param color the text color as a color-int
 * @return a Drawable or null
 */
//* @param textSize the text size in sp
//* @param padding the padding in dp
public static CobaltAbstractFontDrawable getCobaltFontDrawable(Context context, String identifier, int color) {
    mContext = context;
    if (identifier != null) {
        if (identifier.contains(" ")) {
            String[] splitIdentifier = identifier.split(" ");
            String fontName = splitIdentifier[0];
            Class<? extends CobaltAbstractFontDrawable> fontClass = getFonts().get(fontName);
            if (fontClass != null) {
                try {
                    Class[] argsClass = new Class[] { Context.class, String.class, int.class };
                    Object[] arrayArgs = new Object[] { context, splitIdentifier[1], color };
                    Constructor fontConstructor = fontClass.getDeclaredConstructor(argsClass);
                    try {
                        return (CobaltAbstractFontDrawable) fontConstructor.newInstance(arrayArgs);
                    } catch (InstantiationException e) {
                        if (Cobalt.DEBUG)
                            Log.e(TAG, "- getCobaltFontDrawable: exception in Instantiation of fontClass");
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        if (Cobalt.DEBUG)
                            Log.e(TAG, "- getCobaltFontDrawable");
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        if (Cobalt.DEBUG)
                            Log.e(TAG, "- getCobaltFontDrawable");
                        e.printStackTrace();
                    }
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                }
            } else if (Cobalt.DEBUG)
                Log.e(TAG, "- getCobaltFontDrawable: no font class found for name " + fontName + ".");
        } else if (Cobalt.DEBUG)
            Log.e(TAG, TAG + " - getCobaltFontDrawable : no space separate in identifier");
    } else if (Cobalt.DEBUG)
        Log.e(TAG, TAG + " - getCobaltFontDrawable: identifier for icon is null");

    return null;
}

From source file:edu.umn.cs.spatialHadoop.operations.Indexer.java

/***
 * Create a partitioner for a particular job
 * @param in//www  .  ja v a  2  s . c o  m
 * @param out
 * @param job
 * @param partitionerName
 * @return
 * @throws IOException
 */
public static Partitioner createPartitioner(Path[] ins, Path out, Configuration job, String partitionerName)
        throws IOException {
    try {
        Partitioner partitioner = null;
        Class<? extends Partitioner> partitionerClass = PartitionerClasses.get(partitionerName.toLowerCase());
        if (partitionerClass == null) {
            throw new RuntimeException("Unknown index type '" + partitionerName + "'");
        }
        boolean replicate = PartitionerReplicate.get(partitionerName.toLowerCase());
        job.setBoolean("replicate", replicate);
        partitioner = partitionerClass.newInstance();

        long t1 = System.currentTimeMillis();
        final Rectangle inMBR = (Rectangle) OperationsParams.getShape(job, "mbr");
        // Determine number of partitions
        long inSize = 0;
        for (Path in : ins) {
            inSize += FileUtil.getPathSize(in.getFileSystem(job), in);
        }
        long estimatedOutSize = (long) (inSize * (1.0 + job.getFloat(SpatialSite.INDEXING_OVERHEAD, 0.1f)));
        FileSystem outFS = out.getFileSystem(job);
        long outBlockSize = outFS.getDefaultBlockSize(out);
        int numPartitions = Math.max(1, (int) Math.ceil((float) estimatedOutSize / outBlockSize));
        LOG.info("Partitioning the space into " + numPartitions + " partitions");

        final Vector<Point> sample = new Vector<Point>();
        float sample_ratio = job.getFloat(SpatialSite.SAMPLE_RATIO, 0.01f);
        long sample_size = job.getLong(SpatialSite.SAMPLE_SIZE, 100 * 1024 * 1024);

        LOG.info("Reading a sample of " + (int) Math.round(sample_ratio * 100) + "%");
        ResultCollector<Point> resultCollector = new ResultCollector<Point>() {
            @Override
            public void collect(Point p) {
                sample.add(p.clone());
            }
        };
        OperationsParams params2 = new OperationsParams(job);
        params2.setFloat("ratio", sample_ratio);
        params2.setLong("size", sample_size);
        params2.setClass("outshape", Point.class, Shape.class);
        Sampler.sample(ins, resultCollector, params2);
        long t2 = System.currentTimeMillis();
        System.out.println("Total time for sampling in millis: " + (t2 - t1));
        LOG.info("Finished reading a sample of " + sample.size() + " records");

        partitioner.createFromPoints(inMBR, sample.toArray(new Point[sample.size()]), numPartitions);

        return partitioner;
    } catch (InstantiationException e) {
        e.printStackTrace();
        return null;
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:de.clusteval.data.dataset.format.DataSetFormat.java

/**
 * This method parses a dataset format from the given string, containing a
 * dataset format class name and a given dataset format version.
 * /*from  w  ww .j  a va 2 s  .  com*/
 * @param repository
 *            The repository where to look up the dataset format class.
 * @param datasetFormat
 *            The dataset format class name as string.
 * @param formatVersion
 *            The version of the dataset format.
 * @return The parsed dataset format.
 * @throws UnknownDataSetFormatException
 */
public static DataSetFormat parseFromString(final Repository repository, String datasetFormat,
        final int formatVersion) throws UnknownDataSetFormatException {
    Class<? extends DataSetFormat> c = repository.getRegisteredClass(DataSetFormat.class,
            "de.clusteval.data.dataset.format." + datasetFormat);
    try {
        Constructor<? extends DataSetFormat> constr = c.getConstructor(Repository.class, boolean.class,
                long.class, File.class, int.class);
        // changed 21.03.2013: do not register dataset formats here
        return constr.newInstance(repository, false, System.currentTimeMillis(), new File(datasetFormat),
                formatVersion);
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {

    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
    throw new UnknownDataSetFormatException("\"" + datasetFormat + "\" is not a known dataset format.");
}

From source file:com.projity.util.ClassUtils.java

/**
 * Given a type, return its default value.  If type is unknown, a new one is constructed
 * @param clazz//from   w w  w .  jav  a  2s.c  om
 * @return
 */
public static Object getDefaultValueForType(Class clazz) {
    if (clazz == String.class)
        return defaultString;
    else if (clazz == Double.class || clazz == Double.TYPE)
        return defaultDouble;
    else if (clazz == Integer.class || clazz == Integer.TYPE)
        return defaultInteger;
    else if (clazz == Long.class || clazz == Long.TYPE)
        return defaultLong;
    else if (clazz == Float.class || clazz == Float.TYPE)
        return defaultFloat;
    else if (clazz == Boolean.class)
        return defaultBoolean;
    else if (clazz == Rate.class)
        return defaultRate;
    else {
        try {
            System.out.println("making default for class" + clazz);
            return clazz.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}

From source file:org.openml.weka.algorithm.WekaAlgorithm.java

public static String getVersion(String algorithm) {
    String version = "undefined";
    try {//from   w ww . j a va  2 s.c  o  m
        RevisionHandler classifier = (RevisionHandler) Class.forName(algorithm).newInstance();
        if (StringUtils.isAlphanumeric(classifier.getRevision())) {
            version = classifier.getRevision();
        }
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return version;
}

From source file:com.jdo.CloudContactUtils.java

public static Object cloneEntity(Object obj) {
    Object obj1 = null;//from  w  w  w . j a  v a 2  s  .  c  om
    try {
        obj1 = obj.getClass().newInstance();

        Field f[] = obj.getClass().getDeclaredFields();

        for (Field f1 : f) {

            if (!java.lang.reflect.Modifier.isStatic(f1.getModifiers())) {

                f1.setAccessible(true);

                f1.set(obj1, f1.get(obj));
            }
        }
    } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return obj1;

}

From source file:org.ymkm.lib.controller.support.ControlledDialogFragment.java

/**
 * Instantiates a new {@linkplain ControllableFragment} of specified
 * {@code Class}, whose handler will run in the specified Looper
 * /*from   w w w  .j  a va 2s.c  om*/
 * @param f
 *            the subclass of {@linkplain ControlledDialogFragment} to instantiate
 * @param runsInOwnThread
 *            {@code true} if a new thread should be created for this
 *            fragment, {@code false} to let it run in the current thread
 * @return A new instance of {@linkplain ControllableFragment}
 * @throws ControllableFragmentException
 *             if instantiation failed
 */
public static ControllableFragment createFragment(Class<? extends ControllableFragment> f,
        boolean runsInOwnThread, Bundle args) throws ControllableFragmentException {
    assert (null != args);
    try {
        ControlledDialogFragment fragment = (ControlledDialogFragment) f.newInstance();
        args.putBoolean("__new_thread__", runsInOwnThread);
        fragment.setArguments(args);
        return fragment;
    } catch (java.lang.InstantiationException e) {
        e.printStackTrace();
        throw new ControllableFragmentException(e.getMessage());
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        throw new ControllableFragmentException(e.getMessage());
    }
}

From source file:com.parse.simple.SimpleParse.java

public synchronized static <T> T load(Class<T> from, ParseObject to) {
    String id = to.getObjectId();
    T object = null;//  w ww.  j  a v a  2  s  .  com

    if (SimpleParseCache.get().parseObjectsCache.containsKey(id)) {
        object = (T) SimpleParseCache.get().parseObjectsCache.get(id);
        return object;
    }

    try {
        object = from.newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    object = load(object, to);
    SimpleParseCache.get().parseObjectsCache.put(id, object);

    return object;
}

From source file:org.java.plugin.boot.Boot.java

private static BootErrorHandler getErrorHandlerInstance(final String handler, final boolean isServiceApp) {
    if (handler != null) {
        try {/*from  ww w .java  2  s.  c  om*/
            return (BootErrorHandler) Class.forName(handler).newInstance();
        } catch (InstantiationException ie) {
            System.err.println("failed instantiating error handler " //$NON-NLS-1$
                    + handler);
            ie.printStackTrace();
        } catch (IllegalAccessException iae) {
            System.err.println("failed instantiating error handler " //$NON-NLS-1$
                    + handler);
            iae.printStackTrace();
        } catch (ClassNotFoundException cnfe) {
            System.err.println("failed instantiating error handler " //$NON-NLS-1$
                    + handler);
            cnfe.printStackTrace();
        }
    }
    return isServiceApp ? new BootErrorHandlerConsole() : (BootErrorHandler) new BootErrorHandlerGui();
}

From source file:org.mwc.debrief.editable.test.EditableTests.java

/**
* test helper, to check that all of the object property getters/setters are
* there/*  www. j  a  v  a2s  .c o m*/
* 
* @param toBeTested
*/
public static void testTheseParameters(final Editable toBeTested) {
    // check if we received an object
    System.out.println("testing " + toBeTested.getClass());
    if (toBeTested == null)
        return;

    Assert.assertNotNull("Found editable object", toBeTested);

    final Editable.EditorType et = toBeTested.getInfo();

    if (et == null) {
        Assert.fail("no editor type returned for");
        return;
    }

    // first see if we return a custom bean descriptor
    final BeanDescriptor desc = et.getBeanDescriptor();

    // did we get one?
    if (desc != null) {
        final Class<?> editorClass = desc.getCustomizerClass();
        if (editorClass != null) {
            Object newInstance = null;
            try {
                newInstance = editorClass.newInstance();
            } catch (final InstantiationException e) {
                e.printStackTrace(); // To change body of catch statement use File
                                     // | Settings | File Templates.
            } catch (final IllegalAccessException e) {
                e.printStackTrace(); // To change body of catch statement use File
                                     // | Settings | File Templates.
            }
            // check it worked
            Assert.assertNotNull("we didn't create the custom editor for:", newInstance);
        } else {
            // there isn't a dedicated editor, try the custom ones.
            // do the edits
            PropertyDescriptor[] pd = null;
            try {
                pd = et.getPropertyDescriptors();
            } catch (Exception e) {
                org.mwc.debrief.editable.test.Activator.log(e);
                Assert.fail("problem fetching property editors for " + toBeTested.getClass());
            }

            if (pd == null) {
                Assert.fail("problem fetching property editors for " + toBeTested.getClass());
                return;
            }

            final int len = pd.length;
            if (len == 0) {
                System.out.println(
                        "zero property editors found for " + toBeTested + ", " + toBeTested.getClass());
                return;
            }

            // griddable property descriptors
            if (et instanceof Griddable) {
                pd = null;
                try {
                    pd = ((Griddable) et).getGriddablePropertyDescriptors();
                } catch (Exception e) {
                    org.mwc.debrief.editable.test.Activator.log(e);
                    Assert.fail("problem fetching griddable property editors for " + toBeTested.getClass());
                }

                if (pd == null) {
                    Assert.fail("problem fetching griddable property editors for " + toBeTested.getClass());
                    return;
                }
            }
            // the method names are checked when creating PropertyDescriptor
            // we haven't to test them

        } // whether there was a customizer class
    } // whether there was a custom bean descriptor

    // now try out the methods
    final MethodDescriptor[] methods = et.getMethodDescriptors();
    if (methods != null) {
        for (int thisM = 0; thisM < methods.length; thisM++) {
            final MethodDescriptor method = methods[thisM];
            final Method thisOne = method.getMethod();
            final String theName = thisOne.getName();
            Assert.assertNotNull(theName);
        }
    }
}