Java tutorial
//package com.java2s; import java.lang.reflect.Field; public class Main { public static int getResId(String resName, Class<?> c) { try { Field idField = c.getField(resName); return idField.getInt(null); } catch (Exception e) { return -1; } } }