本文整理了Java中java.lang.NoSuchFieldException
类的一些代码示例,展示了NoSuchFieldException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NoSuchFieldException
类的具体详情如下:
包路径:java.lang.NoSuchFieldException
类名称:NoSuchFieldException
[英]Thrown when the VM notices that a program tries to reference, on a class or object, a field that does not exist.
[中]当VM注意到程序试图在类或对象上引用不存在的字段时引发。
代码示例来源:origin: libgdx/libgdx
/** @param name the name of the field
* @return the public field of this type or one of its super interfaces with the given name. See
* {@link Class#getField(String)}.
* @throws NoSuchFieldException */
public Field getField (String name) throws NoSuchFieldException {
for (Field f : getFields()) {
if (f.name.equals(name)) return f;
}
throw new NoSuchFieldException();
}
代码示例来源:origin: Bilibili/DanmakuFlameMaster
static void initField() {
try {
nativeIntField = Bitmap.Config.class.getDeclaredField("nativeInt");
nativeIntField.setAccessible(true);
} catch (NoSuchFieldException e) {
nativeIntField = null;
e.printStackTrace();
}
}
代码示例来源:origin: wildfly/wildfly
public Field run() {
try {
return clazz.getDeclaredField(name);
} catch (NoSuchFieldException e) {
throw new NoSuchFieldError(e.getMessage());
}
}
}
代码示例来源:origin: Meituan-Dianping/Robust
private static Field getReflectStaticField(String name, Class clazz) throws NoSuchFieldException {
try {
Field field = clazz.getDeclaredField(name);
if (!field.isAccessible()) {
field.setAccessible(true);
}
return field;
} catch (NoSuchFieldException e) {
// ignore and search next
e.printStackTrace();
}
throw new NoSuchFieldException("Field " + name + " not found in " + clazz);
}
}
代码示例来源:origin: redisson/redisson
/**
* Is invoked when <code>static</code> fields of the base-level
* class are modified and the runtime system intercepts it.
* This method simply sets the field to the given value.
*
* <p>Every subclass of this class should redefine this method.
*/
public void trapFieldWrite(String name, Object value) {
Class jc = getJavaClass();
try {
jc.getField(name).set(null, value);
}
catch (NoSuchFieldException e) {
throw new RuntimeException(e.toString());
}
catch (IllegalAccessException e) {
throw new RuntimeException(e.toString());
}
}
代码示例来源:origin: redisson/redisson
/**
* Is invoked when <code>static</code> fields of the base-level
* class are read and the runtime system intercepts it.
* This method simply returns the value of the field.
*
* <p>Every subclass of this class should redefine this method.
*/
public Object trapFieldRead(String name) {
Class jc = getJavaClass();
try {
return jc.getField(name).get(null);
}
catch (NoSuchFieldException e) {
throw new RuntimeException(e.toString());
}
catch (IllegalAccessException e) {
throw new RuntimeException(e.toString());
}
}
代码示例来源:origin: libgdx/libgdx
/** @param name the name of the field
* @return the declared field of this type. See {@link Class#getDeclaredField(String)}.
* @throws NoSuchFieldException */
public Field getDeclaredField (String name) throws NoSuchFieldException {
for (Field f : getDeclaredFields()) {
if (f.name.equals(name)) return f;
}
throw new NoSuchFieldException();
}
代码示例来源:origin: rey5137/material
public ListViewCompat(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
try {
mIsChildViewEnabled = AbsListView.class.getDeclaredField("mIsChildViewEnabled");
mIsChildViewEnabled.setAccessible(true);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
}
@Override
代码示例来源:origin: wildfly/wildfly
public Field run() {
final Field field;
try {
field = clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
throw new NoSuchFieldError(e.getMessage());
}
field.setAccessible(true);
return field;
}
}
代码示例来源:origin: apache/hbase
public DefaultMetricsSystemHelper() {
Class<? extends DefaultMetricsSystem> clazz = DefaultMetricsSystem.INSTANCE.getClass();
Method m;
try {
m = clazz.getDeclaredMethod("removeObjectName", String.class);
m.setAccessible(true);
} catch (NoSuchMethodException e) {
m = null;
}
removeObjectMethod = m;
Field f1, f2;
try {
f1 = clazz.getDeclaredField("sourceNames");
f1.setAccessible(true);
f2 = UniqueNames.class.getDeclaredField("map");
f2.setAccessible(true);
} catch (NoSuchFieldException e) {
LOG.trace(e.toString(), e);
f1 = null;
f2 = null;
}
sourceNamesField = f1;
mapField = f2;
}
代码示例来源:origin: libgdx/libgdx
/** @param name the name of the field
* @return the declared field of this type. See {@link Class#getDeclaredField(String)}.
* @throws NoSuchFieldException */
public Field getDeclaredField (String name) throws NoSuchFieldException {
for (Field f : getDeclaredFields()) {
if (f.name.equals(name)) return f;
}
throw new NoSuchFieldException();
}
代码示例来源:origin: aa112901/remusic
void setStGradientPositions(Drawable.ConstantState constantState, float... positions) {
try {
if (sStGradientPositions == null) {
sStGradientPositions = Class.forName("android.graphics.drawable.GradientDrawable$GradientState").getDeclaredField("mPositions");
sStGradientPositions.setAccessible(true);
}
sStGradientPositions.set(constantState, positions);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
代码示例来源:origin: wildfly/wildfly
public Unsafe run() {
try {
final Field field = Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
return (Unsafe) field.get(null);
} catch (IllegalAccessException e) {
throw new IllegalAccessError(e.getMessage());
} catch (NoSuchFieldException e) {
throw new NoSuchFieldError(e.getMessage());
}
}
});
代码示例来源:origin: redisson/redisson
/**
* Is invoked when public fields of the base-level
* class are modified and the runtime system intercepts it.
* This method simply sets the field to the given value.
*
* <p>Every subclass of this class should redefine this method.
*/
public void trapFieldWrite(String name, Object value) {
Class jc = getClassMetaobject().getJavaClass();
try {
jc.getField(name).set(getObject(), value);
}
catch (NoSuchFieldException e) {
throw new RuntimeException(e.toString());
}
catch (IllegalAccessException e) {
throw new RuntimeException(e.toString());
}
}
代码示例来源:origin: libgdx/libgdx
/** @param name the name of the field
* @return the public field of this type or one of its super interfaces with the given name. See
* {@link Class#getField(String)}.
* @throws NoSuchFieldException */
public Field getField (String name) throws NoSuchFieldException {
for (Field f : getFields()) {
if (f.name.equals(name)) return f;
}
throw new NoSuchFieldException();
}
代码示例来源:origin: aa112901/remusic
void setStGradientAngle(Drawable.ConstantState constantState, int angle) {
try {
if (sStGradientAngle == null) {
sStGradientAngle = Class.forName("android.graphics.drawable.GradientDrawable$GradientState").getDeclaredField("mAngle");
sStGradientAngle.setAccessible(true);
}
sStGradientAngle.set(constantState, angle);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
代码示例来源:origin: com.sun.xml.bind/jaxb-impl
public Field[] getEnumConstants(Class clazz) {
try {
Object[] values = clazz.getEnumConstants();
Field[] fields = new Field[values.length];
for (int i = 0; i < values.length; i++) {
fields[i] = clazz.getField(((Enum) values[i]).name());
}
return fields;
} catch (NoSuchFieldException e) {
// impossible
throw new NoSuchFieldError(e.getMessage());
}
}
代码示例来源:origin: redisson/redisson
/**
* Is invoked when public fields of the base-level
* class are read and the runtime system intercepts it.
* This method simply returns the value of the field.
*
* <p>Every subclass of this class should redefine this method.
*/
public Object trapFieldRead(String name) {
Class jc = getClassMetaobject().getJavaClass();
try {
return jc.getField(name).get(getObject());
}
catch (NoSuchFieldException e) {
throw new RuntimeException(e.toString());
}
catch (IllegalAccessException e) {
throw new RuntimeException(e.toString());
}
}
代码示例来源:origin: spullara/mustache.java
protected void checkField(Field member) throws NoSuchFieldException {
if ((member.getModifiers() & Modifier.PRIVATE) == Modifier.PRIVATE) {
throw new NoSuchFieldException("Only public, protected and package members allowed");
}
}
代码示例来源:origin: bluejamesbond/TextJustify-Android
protected static void replaceFont(String staticTypefaceFieldName,
final Typeface newTypeface) {
try {
final Field staticField = Typeface.class
.getDeclaredField(staticTypefaceFieldName);
staticField.setAccessible(true);
staticField.set(null, newTypeface);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!