title: How can I fix this unusual bug that is causing my android app to crash on certain phones?
body: <p>I have recently completed development on a game for Android smartphones.</p>
  
  <p>It was designed using the android 2.1 sdk and runs no problem on my test devices a 2.1 samsung galaxy europa and a 2.2 samsung galaxy tab and seems to run fine in the emulator for 2.3.3.</p>
  
  <p>Up until recently it ran fine on my friends HTC desire S but suddenly it stopped working, crashing on start. </p>
  
  <p>The android developer console spit out this log when from the crash:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.survivaltraildemo/com.survivaltraildemo.SurvivalTrail}: android.content.res.Resources$NotFoundException: Resource ID #0x0
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
  at android.app.ActivityThread.access$1500(ActivityThread.java:132)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:143)
  at android.app.ActivityThread.main(ActivityThread.java:4196)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:507)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
  at dalvik.system.NativeStart.main(Native Method)
  Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
  at android.content.res.Resources.getValue(Resources.java:901)
  at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:547)
  at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:605)
  at com.survivaltraildemo.StaticValues.loadInventory(StaticValues.java:609)
  at com.survivaltraildemo.SurvivalTrail.onCreate(SurvivalTrail.java:31)  
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
  ... 11 more
  </code></pre>
  
  <p>It would appear that the error is caused by a resource not being found when the loadInventory method is run at then end of the onCreate method of the first activity.</p>
  
  <p>The load inventory method takes the Context of the activity.</p>
  
  <p>Here is the offending bit of code:</p>
  
  <pre><code>int id = context.getResources().getIdentifier(name.toLowerCase(),"drawable",context.getPackageName());
                    bullet_images.add(BitmapFactory.decodeResource(context.getResources(),id));
  </code></pre>
  
  <p>This code has not been touched for the past 2 months and ran no problem on my 2.1 and 2.2 devices but I must have done something. It seems that suddenly that some phones can't see the resources but unfortunately I cannot replicate this bug and my friend is not around enough and is getting quite pissed at me for pestering him for me to take his phone and keep trying to fix it.</p>
  
  <p>Any help would be much appreciated as this is driving me mad especially as I cannot replicate this bug with any of my equipment. I haven't even got a confirmation that it works on 2.3.3 as the people who have downloaded my app aren't leaving any useful feedback or submitting many error reports. Hopefully it is just a bug with HTC's variant of android.</p>
  
  <p>If you want to try the app yourself to see if it will happen on you phones here is the demo on the Android Market 
  <a href="https://market.android.com/details?id=com.survivaltraildemo&amp;feature=search_result" rel="nofollow">https://market.android.com/details?id=com.survivaltraildemo&amp;feature=search_result</a></p>