Java tutorial
//package com.java2s; import android.content.Context; public class Main { public static int getResourceId(Context context, String key, String type) throws RuntimeException { int resource = context.getResources().getIdentifier(key, type, context.getPackageName()); if (resource == 0) { throw new RuntimeException("Missing resource " + key); } return resource; } }