I'm attempting to set the background of a layout from a numeric filename (it has to be numeric - this cannot be change) string (the image is 1170.png).
I attempted to use the following example:
Android drawables : Is there any way to somehow link the int IDs to the R drawable IDs?
However when I do the result is the following:
06-03 08:36:47.551: E/AndroidRuntime(1765): FATAL EXCEPTION: main
06-03 08:36:47.551: E/AndroidRuntime(1765): Process: com.app.example, PID: 1765
06-03 08:36:47.551: E/AndroidRuntime(1765): android.content.res.Resources$NotFoundException: Resource ID #0x8c5
06-03 08:36:47.551: E/AndroidRuntime(1765): at android.content.res.Resources.getValue(Resources.java:1123)
06-03 08:36:47.551: E/AndroidRuntime(1765): at android.content.res.Resources.getDrawable(Resources.java:698)
06-03 08:36:47.551: E/AndroidRuntime(1765): at android.view.View.setBackgroundResource(View.java:15303)
06-03 08:36:47.551: E/AndroidRuntime(1765): at com.app.example.MainActivity$1.handleMessage(MainActivity.java:163)
06-03 08:36:47.551: E/AndroidRuntime(1765): at com.app.example.ServiceManager$IncomingHandler.handleMessage(ServiceManager.java:28)
06-03 08:36:47.551: E/AndroidRuntime(1765): at android.os.Handler.dispatchMessage(Handler.java:102)
06-03 08:36:47.551: E/AndroidRuntime(1765): at android.os.Looper.loop(Looper.java:136)
06-03 08:36:47.551: E/AndroidRuntime(1765): at android.app.ActivityThread.main(ActivityThread.java:5001)
06-03 08:36:47.551: E/AndroidRuntime(1765): at java.lang.reflect.Method.invokeNative(Native Method)
06-03 08:36:47.551: E/AndroidRuntime(1765): at java.lang.reflect.Method.invoke(Method.java:515)
06-03 08:36:47.551: E/AndroidRuntime(1765): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
06-03 08:36:47.551: E/AndroidRuntime(1765): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
06-03 08:36:47.551: E/AndroidRuntime(1765): at dalvik.system.NativeStart.main(Native Method)
My code snippet is as follows - it seems correct - but there seems to be something wrong with it (obviously). Can anyone spot what I may have done wrong in this instance?
String SnapShotFrame_TblTriviaLU = "1170";
RelativeLayout relativeLayout2 = (RelativeLayout) findViewById(R.id.gameplayLayout);
int resId = getResources().getIdentifier(SnapShotFrame_TblTriviaLU, "drawable", getPackageName());
relativeLayout2.setBackgroundResource(resId);