Reputation: 75
I want to get the field name of class in android. for this I am using this code
public static String checkForNull(Object obj) {
Class cls = obj.getClass();
Field fields[] = cls.getDeclaredFields();
for (Field field : fields) {
Object object = null;
try {
object = field.get(obj);
} catch (IllegalAccessException e) {
return "The field " + field.getName() + " of " + cls.getSimpleName() + " is not accessible!";
}
if (object == null) {
return "The field " + field.getName() + " of " + cls.getSimpleName() + " is null!";
} else if (object instanceof String) {
String string = (String) object;
if (string.equals("")) {
return "The field " + field.getName() + " of " + cls.getSimpleName() + " is empty!";
}
}
}
return null;
}
but this code return generic name of class field like a,b,c...etc. This code work fine in netbeans.
Upvotes: 1
Views: 1507
Reputation: 1126
Looks like obfuscated names, most probably you have default settings for ProGuard and Android SDK performs some code obfuscation, see https://developer.android.com/studio/build/shrink-code.html
If you would like to see original field names, you should disable obfuscation either completely or for this particular class / package.
Upvotes: 1