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