title: Nullpointer Exception with image gallery
body: <p>i get string theme_name in database sqlite and then use theme name to set a image in gallery . But i have some error with nullpointer exception. Can you tell me why happen ? and how can i do ? Thank you</p>
  
  <p>this is my code</p>
  
  <pre><code> public class MybookActivity_Gallery extends Activity{
  
  private BooksDB db;
  private Context context;
  private HashMap&lt; String, ArrayList&lt;String&gt;&gt; hm;
  private ImageView imgOldSelected;
  private int resID;
  private ImageView img_shelf;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.layout_mybookactivity_gallery);
      context = this;
      db = new BooksDB(context);
      ArrayList&lt;String&gt; list_bokID = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; list_title = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; list_theme = new ArrayList&lt;String&gt;();
      hm = new HashMap&lt;String, ArrayList&lt;String&gt;&gt;();
  
      //get Theme_name
      hm = db.getBookTheme();
      if(hm.isEmpty() == true){
          System.out.println("not have data");
      }else{
          //prepare theme, title, book_id 
          list_theme = hm.get("theme");
          list_title = hm.get("title");
          list_bokID = hm.get("bokID");
      }
  
      LinearLayout gallery = (LinearLayout)findViewById(R.id.images_gallery);
      //image fullsize 
      final ImageView imgFullSize = (ImageView)findViewById(R.id.full_size_image);
  
      for (String themeName : list_theme) {
          //prepare image in layout gallery 
          ImageView img_shelf = new ImageView(this);
          img_shelf.setLayoutParams(new LinearLayout.LayoutParams(150, 150));
          img_shelf.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
          img_shelf.setPadding(8, 8, 8, 8);
          //set image resource
          resID = getResources().getIdentifier(themeName, "drawable", getPackageName());
          img_shelf.setImageResource(resID);
  
  
      }
  
      // img_shelf set it in on click
                  img_shelf.setOnClickListener(new View.OnClickListener() {
  
                      @Override
                      public void onClick(View v) {
  
                          ImageView selectedImage = (ImageView) v;
                          Bitmap bitmap = ((BitmapDrawable) selectedImage.getDrawable()).getBitmap();
  
                          if(imgOldSelected != null){
                              imgOldSelected.setBackgroundColor(Color.TRANSPARENT);
                          }
                          selectedImage.setBackgroundColor(Color.LTGRAY);
  
                      }
                  });
  
                  gallery.addView(img_shelf);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>this is my logcat error</p>
  
  <pre><code> 02-21 16:12:02.421: E/AndroidRuntime(29116): FATAL EXCEPTION: main
   02-21 16:12:02.421: E/AndroidRuntime(29116): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.splash.bookguk_project/category_viewbook_sub2_1.MybookActivity_Gallery}: java.lang.NullPointerException
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at android.app.ActivityThread.access$700(ActivityThread.java:140)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at android.os.Handler.dispatchMessage(Handler.java:99)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at android.os.Looper.loop(Looper.java:137)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at android.app.ActivityThread.main(ActivityThread.java:4921)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at java.lang.reflect.Method.invokeNative(Native Method)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at java.lang.reflect.Method.invoke(Method.java:511)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at dalvik.system.NativeStart.main(Native Method)
   02-21 16:12:02.421: E/AndroidRuntime(29116): Caused by: java.lang.NullPointerException
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at category_viewbook_sub2_1.MybookActivity_Gallery.onCreate(MybookActivity_Gallery.java:73)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at android.app.Activity.performCreate(Activity.java:5206)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
   02-21 16:12:02.421: E/AndroidRuntime(29116):   ... 11 more
  </code></pre>
  
  <p>thank you</p>