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

/**
 * Get the API access token request uri//from w w  w.j  ava2s. co m
 *
 * @param cloudApi type of cloud account
 * @return Uri
 */
public static Uri getAccessTokenUri(String cloudApi) throws MalformedURLException {
    // use reflection for flexibility
    try {
        Class clazz = Class.forName(cloudApi);
        Field tokenUrl = clazz.getField("TOKEN_URL");
        return Uri.parse((String) tokenUrl.get(null));
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    throw new MalformedURLException("No url or malformed url for request!");
}

From source file:Main.java

/**
 * is set class//from w w w.j  a  v a  2  s  .c om
 */
public static boolean isSet(String type) {
    if (type == null) {
        return true;
    }
    try {
        Class<?> c = Class.forName(type);
        if (Set.class.isAssignableFrom(c)) {
            return true;
        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    return false;

}

From source file:Main.java

public static Object deserialize(byte[] bytes) {
    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    ObjectInput in = null;//from w  ww  .j a v  a  2  s  .c om
    Object o = null;
    try {
        in = new ObjectInputStream(bis);
        o = in.readObject();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            bis.close();
        } catch (IOException ex) {
            // ignore close exception
        }
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException ex) {
            // ignore close exception
        }
    }
    return o;
}

From source file:Main.java

/**
 * Build authorization url base on type of cloud service
 *
 * @param cloudApi type of cloud account
 * @return Uri/* w w w.  ja va  2  s  .  com*/
 */
public static Uri buildAuthUri(String cloudApi, String stateString) {
    // use reflection for flexibility
    try {
        Class<?> clazz = Class.forName(cloudApi);
        Method buildAuthUri = clazz.getMethod("buildAuthUri", String.class);
        return (Uri) buildAuthUri.invoke(null, stateString);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

public static String getId(Context context) {
    String id = null;// w w w .  j av  a2s.c  om

    try {
        Class aicclass = Class.forName("com.google.android.gms.ads.identifier.AdvertisingIdClient");
        Method m1 = aicclass.getMethod("getAdvertisingIdInfo", Context.class);
        Object oInfo = m1.invoke(null, context);

        Class infoclass = Class.forName("com.google.android.gms.ads.identifier.AdvertisingIdClient$Info");
        Method m2 = infoclass.getMethod("getId");

        id = (String) m2.invoke(oInfo);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        e.printStackTrace();
    }

    return id;

}

From source file:Main.java

/**
 * Enable/Disable mobile data.//from  w w w.j  a v a 2 s . c o  m
 * @param context
 * @param enabled
 */
public static void setMobileDataEnabled(Context context, boolean enabled) {
    try {
        final ConnectivityManager conman = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        final Class conmanClass = Class.forName(conman.getClass().getName());
        final Field connectivityManagerField = conmanClass.getDeclaredField("mService");
        connectivityManagerField.setAccessible(true);
        final Object connectivityManager = connectivityManagerField.get(conman);
        final Class connectivityManagerClass = Class.forName(connectivityManager.getClass().getName());
        final Method setMobileDataEnabledMethod = connectivityManagerClass
                .getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
        setMobileDataEnabledMethod.setAccessible(true);
        // Method call for enabling mobile data..
        setMobileDataEnabledMethod.invoke(connectivityManager, enabled);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static int getStatusHeight(Activity activity) {
    int statusHeight = 0;
    Rect localRect = new Rect();
    activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(localRect);
    statusHeight = localRect.top;/*  w ww. j  a  va  2 s.co m*/
    if (0 == statusHeight) {
        Class<?> localClass;
        try {
            localClass = Class.forName("com.android.internal.R$dimen");
            Object localObject = localClass.newInstance();
            int i5 = Integer.parseInt(localClass.getField("status_bar_height").get(localObject).toString());
            statusHeight = activity.getResources().getDimensionPixelSize(i5);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }
    return statusHeight;
}

From source file:Main.java

public static int getIdByName(Context context, String className, String name) {
    String packageName = context.getPackageName();
    Class r = null;// w w  w . j  av  a 2s .  com
    int id = 0;
    try {
        r = Class.forName(packageName + ".R");

        Class[] classes = r.getClasses();
        Class desireClass = null;

        for (int i = 0; i < classes.length; ++i) {
            if (classes[i].getName().split("\\$")[1].equals(className)) {
                desireClass = classes[i];
                break;
            }
        }
        if (classes.length == 0) {
            desireClass = Class.forName(packageName + ".R$" + className);
        }
        if (desireClass != null)
            id = desireClass.getField(name).getInt(desireClass);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }

    return id;
}

From source file:Main.java

/**
 * /*from  w  w  w .  j  a  va2s  .  c o  m*/
 * @param node
 * @param classname
 * @return
 */
public static Object decode(Element node, String classname) {
    try {
        Class classObject = Class.forName(classname);
        Object object = classObject.newInstance();
        NamedNodeMap attributes = node.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
            Node child = attributes.item(i);
            String nodeName = child.getNodeName();
            Field field = classObject.getField(nodeName);
            field.setAccessible(true);
            field.set(object, child.getNodeValue());
        }
        return object;
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return null;
    } catch (InstantiationException e) {
        e.printStackTrace();
        return null;
    } catch (IllegalAccessException e) {
        e.printStackTrace();
        return null;
    } catch (SecurityException e) {
        e.printStackTrace();
        return null;
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
        return null;
    }

}

From source file:Main.java

public static Class<?> getClass(String className) {
    if (TextUtils.isEmpty(className)) {
        return null;
    }// w w  w  . j  av a  2s.  co  m

    try {
        return Class.forName(className);
    } catch (ClassNotFoundException e) {
        if (DEBUG) {
            e.printStackTrace();
        }
    }

    return null;
}