Example usage for java.lang NoSuchFieldException printStackTrace

List of usage examples for java.lang NoSuchFieldException printStackTrace

Introduction

In this page you can find the example usage for java.lang NoSuchFieldException 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

/**
 * An utility function that returns the menu identifier for a particular
 * menu item.//from   w  ww  .j  ava  2  s  .  c  om
 * 
 * @param cls Class object of the class that handles the menu ite,.
 * @param identifier Menu identifier.
 * @return The integer corresponding to the menu item.
 */
public static int getMenuIdentifier(Class cls, String identifier) {
    int id = -1;
    try {
        Integer field = (Integer) cls.getDeclaredField(identifier).get(cls);
        id = field.intValue();
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return id;
}

From source file:Main.java

public static long getBitmapNativeId(Bitmap bitmap) {
    if (bitmap == null)
        return 0l;
    if (FILELD_NATIVE_ID == null) {
        try {/*from   www .j av  a 2 s .c  o m*/
            FILELD_NATIVE_ID = Bitmap.class.getDeclaredField("mNativeBitmap");
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        }
    }

    if (FILELD_NATIVE_ID == null)
        return 0l;
    try {
        return FILELD_NATIVE_ID.getLong(bitmap);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return 0l;
}

From source file:Main.java

@Deprecated
public static void quitAppliation(Activity activity) {
    try {/*from   www  .  j a  va  2 s .  c  o m*/
        Class<?> clazz_Activity = Class.forName("android.app.Activity");
        Field field_mMainThread = clazz_Activity.getDeclaredField("mMainThread");
        field_mMainThread.setAccessible(true);
        Object mMainThread = field_mMainThread.get(activity);

        Class<?> clazz_ActivityThread = Class.forName("android.app.ActivityThread");
        Field field_mAppThread = clazz_ActivityThread.getDeclaredField("mAppThread");
        field_mAppThread.setAccessible(true);
        Object mAppThread = field_mAppThread.get(mMainThread);

        Class<?> clazz_ActivityClientRecord = Class.forName("android.app.ActivityThread$ApplicationThread");
        Method method_scheduleExit = clazz_ActivityClientRecord.getDeclaredMethod("scheduleExit");
        method_scheduleExit.invoke(mAppThread);
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

private static BitmapFactory.Options getBitmapOptions(Context context) {
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inScaled = true;//from   w  w  w. ja  v  a2 s  .c  o m
    options.inPreferredConfig = DEFAULT_BITMAP_CONFIG;
    options.inPurgeable = true;
    options.inInputShareable = true;
    options.inJustDecodeBounds = false;
    options.inTempStorage = new byte[DECODE_BUFFER_SIZE];
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
        Field field = null;
        try {
            field = BitmapFactory.Options.class.getDeclaredField("inNativeAlloc");
            field.setAccessible(true);
            field.setBoolean(options, true);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    int displayDensityDpi = context.getResources().getDisplayMetrics().densityDpi;
    float displayDensity = context.getResources().getDisplayMetrics().density;
    int density = 0;
    if (displayDensityDpi > DENSITY_240 && displayDensityDpi <= DENSITY_400 && displayDensity > 1.5f) {
        density = (int) (displayDensityDpi * SCALE_FACTOR);
    } else if (displayDensityDpi > DENSITY_400 && displayDensity > 2.5f) {
        density = (int) (displayDensityDpi * SCALE_FACTOR_2);
    }
    if (density == 0)
        return options;
    options.inDensity = density;
    options.inTargetDensity = density;
    return options;
}

From source file:Main.java

private static Field getField(Class<?> thisClass, String fieldName) {
    Field field = null;/*from  w w w. j av  a  2s.com*/

    if (!TextUtils.isEmpty(fieldName)) {
        try {
            field = thisClass.getDeclaredField(fieldName);
        } catch (NoSuchFieldException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return field;
}

From source file:Main.java

public static void finishAllActivies(Activity activity) {
    try {//from   w  w  w.jav  a 2 s.c om
        Class<?> clazz_Activity = Class.forName("android.app.Activity");
        Field field_mMainThread = clazz_Activity.getDeclaredField("mMainThread");
        field_mMainThread.setAccessible(true);
        Object mMainThread = field_mMainThread.get(activity);

        Class<?> clazz_ActivityThread = Class.forName("android.app.ActivityThread");
        Field field_mActivities = clazz_ActivityThread.getDeclaredField("mActivities");
        field_mActivities.setAccessible(true);
        Object mActivities = field_mActivities.get(mMainThread);

        HashMap<?, ?> map = (HashMap<?, ?>) mActivities;
        Collection<?> collections = map.values();
        if (null != collections && !collections.isEmpty()) {
            Class<?> clazz_ActivityClientRecord = Class
                    .forName("android.app.ActivityThread$ActivityClientRecord");
            Field field_activitiy = clazz_ActivityClientRecord.getDeclaredField("activity");
            field_activitiy.setAccessible(true);

            Activity acti;
            for (Object obj : collections) {
                acti = (Activity) field_activitiy.get(obj);
                Log.d(TAG, "activity.name=" + acti.getClass().getName());
                if (null != acti && !acti.isFinishing()) {
                    Log.d(TAG, "activity.name=" + acti.getClass().getName() + " not finish.");
                    acti.finish();
                }
            }
        }
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static Object getSIGNAL_STRENGTH_NAMES(Object instance) {
    try {/*  www  .  ja va2s .c om*/
        Field f = getField(instance.getClass(), "SIGNAL_STRENGTH_NAMES");
        return f.get(instance);
    } catch (NoSuchFieldException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;

}

From source file:android.support.v7.internal.widget.TintSpinner.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void setPopupBackgroundDrawableV11(Spinner view, Drawable background) {
    try {//  w w w  .j ava2s .  c o m
        Field popupField = Spinner.class.getDeclaredField("mPopup");
        popupField.setAccessible(true);

        Object popup = popupField.get(view);

        if (popup instanceof ListPopupWindow) {
            ((ListPopupWindow) popup).setBackgroundDrawable(background);
        }
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
}

From source file:io.logspace.it.InfrastructureRule.java

private static Field getField(Class<?> type, String fieldName) {
    Class<?> currentType = type;

    while (currentType != null) {
        try {/*from   www . ja  va 2 s .  co m*/
            return currentType.getDeclaredField(fieldName);
        } catch (NoSuchFieldException e) {
            // nothing to do
        } catch (SecurityException e) {
            e.printStackTrace();
        }

        currentType = currentType.getSuperclass();
    }

    return null;
}

From source file:Main.java

public static boolean replaceField(String className, String fieldName, Object desObj, Object fieldObj) {
    Field tempField;/*  w ww  .  j a  v a2 s.c  o m*/
    try {
        tempField = Class.forName(className).getDeclaredField(fieldName);
        tempField.setAccessible(true);
        tempField.set(desObj, fieldObj);
        return true;
    } catch (NoSuchFieldException e) {
        // TODO Auto-generated catch block
        Log.i("DEX", "" + e.getMessage());
        // e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return false;
}