Java tutorial
//package com.java2s; import android.content.Context; import android.util.Log; public class Main { public static int getResourceIdByName(Context context, String className, String name) { int id = 0; if (context == null) { return id; } else { String packageName = context.getPackageName(); try { String var10 = packageName + ".R$" + className; Class desireClass = Class.forName(var10); if (desireClass != null) { id = desireClass.getField(name).getInt(desireClass); } } catch (ClassNotFoundException var7) { Log.d("dou361", "ClassNotFoundException: class=" + className + " fieldname=" + name); } catch (IllegalArgumentException var8) { Log.d("dou361", "IllegalArgumentException: class=" + className + " fieldname=" + name); } catch (SecurityException var9) { Log.d("dou361", "SecurityException: class=" + className + " fieldname=" + name); } catch (IllegalAccessException var101) { Log.d("dou361", "IllegalAccessException: class=" + className + " fieldname=" + name); } catch (NoSuchFieldException var11) { Log.d("dou361", "NoSuchFieldException: class=" + className + " fieldname=" + name); } return id; } } }