title: Show GridView images from JSON Android
body: <p>I have a problem when displaying images from JSON to GridView could help me .</p>
  
  <p>GalleryActivity.java</p>
  
  <pre><code>public class GalleryActivity extends Activity {
  
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.gallery_layout);
  
           Intent i = getIntent();
  
           String tempid = i.getStringExtra("tempid");
  
          GridView gridView = (GridView) findViewById(R.id.grid_view);
  
  
          gridView.setAdapter(new ImageAdapter(this,tempid));
  
  
          gridView.setOnItemClickListener(new OnItemClickListener() {
  
              public void onItemClick(AdapterView&lt;?&gt; parent, View v,
                      int position, long id) {
  
              }
          });
      }
  }
  </code></pre>
  
  <p>ImageAdapter.java</p>
  
  <pre><code>public class ImageAdapter extends BaseAdapter {
      private Context mContext;
  
      public String[] mThumbIds;
  
      private static String KEY_SUCCESS = "success";
  
      private static String KEY_IMAGES = "images";
      private static String KEY_IMAGE = "url_img";
  
  
      // Constructor
      public ImageAdapter(Context c,String tempID){
          mContext = c;
           final DealerFunctions dealerFunction = new DealerFunctions();
           JSONObject json = dealerFunction.getImages(tempID);
  
           try {
  
                  if (json.getString(KEY_SUCCESS) != null) {
  
                      String res = json.getString(KEY_SUCCESS);
                      if (Integer.parseInt(res) == 1) {
  
  
                          JSONArray imagesFields = json
                                  .getJSONArray(KEY_IMAGES);
  
  
                          for (int i = 0; i &lt; imagesFields.length(); i++) {
                              JSONObject x = imagesFields.getJSONObject(i);
  
                              mThumbIds[i] =  x.getString(KEY_IMAGE);
  
  
                          }
  
  
  
                      } else {
  
  
                      }
  
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
  
      }
  
  
      public int getCount() {
          return mThumbIds.length;
      }
  
  
      public Object getItem(int position) {
          return mThumbIds[position];
      }
  
  
      public long getItemId(int position) {
          return 0;
      }
  
  
      public View getView(int position, View convertView, ViewGroup parent) {         
          ImageView imageView;
          if (convertView==null){
  
              imageView = new ImageView(mContext);
               imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
               imageView.setLayoutParams(new GridView.LayoutParams(70, 70));
  
          }else{
              imageView = (ImageView) convertView;
          }
  
          imageView.setBackgroundDrawable(Drawable.createFromPath(mThumbIds[position]));
  
          return imageView;
      }
  
  }
  </code></pre>
  
  <p>Don't Work...</p>
  
  <p>when I run the application, closes immediately assume that the problem comes in imageView.setBackgroundDrawable (Drawable.createFromPath (mThumbIds [position]));</p>
  
  <p>I need your help guys</p>
  
  <p>Logcat Errors as follows.</p>
  
  <pre><code>03-27 10:50:12.658: D/AndroidRuntime(1782): Shutting down VM
  03-27 10:50:12.658: W/dalvikvm(1782): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
  03-27 10:50:12.678: E/AndroidRuntime(1782): FATAL EXCEPTION: main
  03-27 10:50:12.678: E/AndroidRuntime(1782): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.montalvo.dealer/com.montalvo.dealer.GalleryActivity}: java.lang.NullPointerException
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at android.os.Handler.dispatchMessage(Handler.java:99)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at android.os.Looper.loop(Looper.java:123)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at android.app.ActivityThread.main(ActivityThread.java:4627)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at java.lang.reflect.Method.invokeNative(Native Method)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at java.lang.reflect.Method.invoke(Method.java:521)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at dalvik.system.NativeStart.main(Native Method)
  03-27 10:50:12.678: E/AndroidRuntime(1782): Caused by: java.lang.NullPointerException
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at com.montalvo.dealer.ImageAdapter.&lt;init&gt;(ImageAdapter.java:57)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at com.montalvo.dealer.GalleryActivity.onCreate(GalleryActivity.java:25)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
  03-27 10:50:12.678: E/AndroidRuntime(1782):     ... 11 more
  03-27 10:50:15.501: I/Process(1782): Sending signal. PID: 1782 SIG: 9
  </code></pre>