B
B
bars962015-02-14 18:54:27
Java
bars96, 2015-02-14 18:54:27

Why NoSuchFieldException when getDeclaredField() and the presence of the field?

java.lang.NoSuchFieldException: c
at java.lang.Class.getDeclaredField(Unknown Source)
at ru.onlymc.OnlyMZ.CustomEntityType.getPrivateStatic(CustomEntityType.java:177)

Method:
private static Object getPrivateStatic(Class clazz, String f) throws Exception {
  Field field = clazz.getDeclaredField(f);
  field.setAccessible(true);
  return field.get(null);
}

Call:
private static void a(Class paramClass, String paramString, int paramInt) {
  try {
    ((Map) getPrivateStatic(sg.class, "c")).put(paramString, paramClass);
    //...
  } catch (Exception exc) {
    exc.printStackTrace();
  }
}

sg.class (from the decompile to make sure the fields definitely exist) :
private static Map c = new HashMap();
private static Map d = new HashMap();
private static Map e = new HashMap();
private static Map f = new HashMap();
private static Map g = new HashMap();
public static HashMap a = new LinkedHashMap();

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Moxa, 2015-02-14
@Moxa

perhaps a different version of this class is used in runtime, or proguard obfuscated the fields

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question