Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing ArrayList<Bitmap> into another class and convert to Bitmap[]
    primarykey
    data
    text
    <p>I fetch the image URL from my PHP and MySQL database. Everything here is fine, because the <code>Log.d</code> shows the result with a valid image URL.</p> <pre><code>if (success == 1) { JSONArray comments = json.getJSONArray("photos"); for (int i = 0; i &lt; comments.length(); i++) { JSONObject m = comments.getJSONObject(i); final String filename = m.getString("filename"); final String extension = m.getString("extension"); String upload_at = m.getString("upload_at"); String uid = m.getString("uid"); runOnUiThread(new Runnable() { @Override public void run() { Bitmap mThumbIds = fetchImage(filepath_min + filename + "." + extension); Log.d("Photo URL", filepath_min + filename + "." + extension); List&lt;Bitmap&gt; l = Arrays.asList(mThumbIds); photoList = new ArrayList&lt;Bitmap&gt;(l); } }); } } // Instance of ImageAdapter Class mHandler.postDelayed((new Runnable() { public void run() { imgGrid.setAdapter(new ImageAdapter( PhotoViewerActivity.this, photoList)); } }), 1000); </code></pre> <p><br></p> <p>Below this for fetch an image from the given URL and return as Bitmap. Nothing problem here, just for reference want to show that the return is Bitmap.</p> <pre><code>public Bitmap fetchImage(String urlstr) { try { URL url; url = new URL(urlstr); HttpURLConnection c = (HttpURLConnection) url.openConnection(); c.setDoInput(true); c.connect(); InputStream is = c.getInputStream(); Bitmap img; img = BitmapFactory.decodeStream(is); return img; } catch (MalformedURLException e) { Log.d("RemoteImageHandler", "fetchImage passed invalid URL: " + urlstr); } catch (IOException e) { Log.d("RemoteImageHandler", "fetchImage IO exception: " + e); } return null; } </code></pre> <p><br></p> <p>This is my ImageAdapter for viewing image in GridView.</p> <pre><code>public class ImageAdapter extends BaseAdapter { private Context mContext; List&lt;Bitmap&gt; list = new ArrayList&lt;Bitmap&gt; l; public ImageAdapter(Context c, ArrayList&lt;Bitmap&gt; l) { mContext = c; list = l; } public Bitmap[] mThumbIds = list.toArray(new Bitmap[list.size()]); @Override public int getCount() { return mThumbIds.length; } @Override public Object getItem(int position) { return mThumbIds[position]; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { ImageView imageView = new ImageView(mContext); imageView.setImageBitmap(mThumbIds[position]); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setLayoutParams(new GridView.LayoutParams(130, 130)); return imageView; } } </code></pre> <p><br></p> <p>Here is my problem. None image shown on the activity. When I try hardcoded URL with fetch array in Bitmap[] mThumbIds, its was success.</p> <pre><code>Bitmap[] mThumbIds = { fetchImage("http://...jpg"), fetchImage("http://...jpg") } </code></pre> <p>I don't know what's wrong. I've tried <code>Bitmap[] mThumbIds = list.toArray(new Bitmap[list.size()]);</code> to convert ArrayList to Array. <br></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload