List of usage examples for java.lang NoSuchFieldException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void main(String... args) { Main ft = new Main(); try {/*from w ww .ja v a2s .c o m*/ Class<?> c = ft.getClass(); Field f = c.getDeclaredField("b"); f.setAccessible(true); // solution f.setBoolean(ft, Boolean.FALSE); // IllegalAccessException // production code should handle these exceptions more gracefully } catch (NoSuchFieldException x) { x.printStackTrace(); } catch (IllegalArgumentException x) { x.printStackTrace(); } catch (IllegalAccessException x) { x.printStackTrace(); } }
From source file:FieldTroubleToo.java
public static void main(String... args) { FieldTroubleToo ft = new FieldTroubleToo(); try {// w ww. ja v a2 s.c o m Class<?> c = ft.getClass(); Field f = c.getDeclaredField("b"); // f.setAccessible(true); // solution f.setBoolean(ft, Boolean.FALSE); // IllegalAccessException // production code should handle these exceptions more gracefully } catch (NoSuchFieldException x) { x.printStackTrace(); } catch (IllegalArgumentException x) { x.printStackTrace(); } catch (IllegalAccessException x) { x.printStackTrace(); } }
From source file:E0.java
public static void main(String... args) { try {/* ww w . j a v a 2 s.c o m*/ ETest test = new ETest(); Field f = test.getClass().getDeclaredField("fld"); f.setAccessible(true); f.set(test, E1.A); // IllegalArgumentException // production code should handle these exceptions more gracefully } catch (NoSuchFieldException x) { x.printStackTrace(); } catch (IllegalAccessException x) { x.printStackTrace(); } }
From source file:Tweedle.java
public static void main(String... args) { Book book = new Book(); String fmt = "%6S: %-12s = %s%n"; try {// w w w . j a va 2 s .c om Class<?> c = book.getClass(); Field chap = c.getDeclaredField("chapters"); out.format(fmt, "before", "chapters", book.chapters); chap.setLong(book, 12); out.format(fmt, "after", "chapters", chap.getLong(book)); Field chars = c.getDeclaredField("characters"); out.format(fmt, "before", "characters", Arrays.asList(book.characters)); String[] newChars = { "Queen", "King" }; chars.set(book, newChars); out.format(fmt, "after", "characters", Arrays.asList(book.characters)); Field t = c.getDeclaredField("twin"); out.format(fmt, "before", "twin", book.twin); t.set(book, Tweedle.DUM); out.format(fmt, "after", "twin", t.get(book)); // production code should handle these exceptions more gracefully } catch (NoSuchFieldException x) { x.printStackTrace(); } catch (IllegalAccessException x) { x.printStackTrace(); } }
From source file:Main.java
public static Field getDeclaredField(Class clazz, String name) { try {//from ww w .ja v a 2 s. com Field field = clazz.getDeclaredField(name); return field; } catch (NoSuchFieldException e) { e.printStackTrace(); } return null; }
From source file:Main.java
private static void setField(Object obj, Class<?> cls, String field, Object value) { try {//from ww w .ja v a 2 s . co m Field localField = cls.getDeclaredField(field); localField.setAccessible(true); localField.set(obj, value); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
From source file:Main.java
protected static void replaceFont(String staticTypefaceFieldName, final Typeface newTypeface) { try {//ww w.j ava 2s.co m final Field staticField = Typeface.class.getDeclaredField(staticTypefaceFieldName); staticField.setAccessible(true); staticField.set(null, newTypeface); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
From source file:Main.java
public static void injectLayoutInflater(LayoutInflater layoutInflater, Object src, Class clz, String name) { try {/*w ww . ja va 2s . c om*/ Field field = clz.getDeclaredField(name); field.setAccessible(true); field.set(src, layoutInflater); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
From source file:Main.java
public static void init() { try {//from w w w. j a v a 2 s . co m Class AppOpsManager = Class.forName("android.app.AppOpsManager"); Field field = AppOpsManager.getDeclaredField("OP_SYSTEM_ALERT_WINDOW"); field.setAccessible(true); OP_SYSTEM_ALERT_WINDOW = field.getInt(null); } catch (ClassNotFoundException e2) { } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }
From source file:Main.java
public static Field findFields(Class<?> clazz, String fieldName) { Field result = null;/*from ww w . ja va2s . com*/ if (clazz != null) { try { result = clazz.getField(fieldName); } catch (NoSuchFieldException e) { e.printStackTrace(); } } return result; }