Ошибка получения изображений в Listview с сервера с помощью Json

я не получаю свои изображения списка с сервера … он дает мне только изображения Launcher, но не изображение с сервера …

вот моя подменю:

public class SubMenu extends Activity { // Declare Variables JSONObject jsonobject; JSONArray jsonarray; ListView listview; ListViewAdapter adapter; ProgressDialog mProgressDialog; ArrayList<HashMap<String, String>> arraylist; static String RANK = "id"; static String COUNTRY = "name"; static String FLAG = "image"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get the view from listview_main.xml setContentView(R.layout.activity_sub_menu); // Execute DownloadJSON AsyncTask new DownloadJSON().execute(); } // DownloadJSON AsyncTask private class DownloadJSON extends AsyncTask<Void, Void, Void> { // @Override // protected void onPreExecute() { // super.onPreExecute(); // Create a progressdialog // mProgressDialog = new ProgressDialog(SubMenu.this); // Set progressdialog title // mProgressDialog.setTitle("Categories of Main categories....."); // Set progressdialog message // mProgressDialog.setMessage("Loading..."); // mProgressDialog.setIndeterminate(false); // Show progressdialog // mProgressDialog.show(); // } @Override protected Void doInBackground(Void... params) { // Create an array arraylist = new ArrayList<HashMap<String, String>>(); // Retrieve JSON Objects from the given URL address jsonarray = JsonFunctions .getJSONfromURL("http://cloud.granddubai.com/broccoli/menu_typeitem.php"); try { // Locate the array name in JSON // jsonarray = jsonobject.getJSONArray("main_menu_items"); for (int i = 0; i < jsonarray.length(); i++) { HashMap<String, String> map = new HashMap<String, String>(); jsonobject = jsonarray.getJSONObject(i); // Retrive JSON Objects map.put("id", jsonobject.getString("id")); map.put("name", jsonobject.getString("name")); map.put("image", jsonobject.getString("image")); // Set the JSON Objects into the array arraylist.add(map); } } catch (JSONException e) { Log.e("Error", e.getMessage()); e.printStackTrace(); } return null; } @Override protected void onPostExecute(Void args) { // Locate the listview in listview_main.xml listview = (ListView) findViewById(R.id.list1); // Pass the results into ListViewAdapter.java adapter = new ListViewAdapter(SubMenu.this, arraylist); // Set the adapter to the ListView listview.setAdapter(adapter); // Close the progressdialog // mProgressDialog.dismiss(); } } } 

Я новичок в android … еще одна штука несколько снимков недоступна в таблице. Это причина ???? вот мой json:

 [ { "id": "1", "name": "Bianca Pizza", "image": "http://img.ruphp.com/php/Bianca.png" }, { "id": "2", "name": "Cheese Pizza", "image": "http://img.ruphp.com/php/Cheese.png" }, { "id": "3", "name": "Chicken BBQ Pizza:", "image": "http://cloud.granddubai.com/broccoli/uploads/Chicken BBQ.png" }, { "id": "4", "name": "Deluxe Pizza", "image": "http://img.ruphp.com/php/Deluxe.png" }, { "id": "5", "name": "Greek Pizza", "image": "http://img.ruphp.com/php/Greek.png" }, { "id": "6", "name": "Hawaiian Pizza", "image": "http://img.ruphp.com/php/Hawaiian.png" }, { "id": "7", "name": "Meat Lovers Pizza", "image": "http://cloud.granddubai.com/broccoli/uploads/Meat Lovers.png" }, { "id": "8", "name": "Pepperoni Pizza", "image": "" }, { "id": "9", "name": "Shrimp Pizza", "image": "" }, { "id": "10", "name": "Vegetable Pizza", "image": "" }, { "id": "11", "name": "Original Italian Pizza", "image": "" }, { "id": "12", "name": "Beef Strips Pasta", "image": "" }, { "id": "13", "name": "Chicken Pasta", "image": "" }, { "id": "14", "name": "Meat Balls Pasta", "image": "http://cloud.granddubai.com/broccoli/uploads/Meat Lovers.png" }, { "id": "15", "name": "Sausage Pasta", "image": "http://img.ruphp.com/php/Sausage.png" }, { "id": "16", "name": "Shrimp Pasta", "image": "http://img.ruphp.com/php/Shrimp.png" }, { "id": "17", "name": "Vegetable Pasta", "image": "http://img.ruphp.com/php/Vegetable.png" }, { "id": "18", "name": "Pesto Pasta", "image": "http://img.ruphp.com/php/Pesto.png" }, { "id": "19", "name": "Chicken Lasagna", "image": "" }, { "id": "20", "name": "Meat Lasagna", "image": "" }, { "id": "21", "name": "Vegetable Lasagna", "image": "" }, { "id": "22", "name": "Caesar Salad", "image": "http://img.ruphp.com/php/Caesar.png" }, { "id": "23", "name": "Chicken Caesar Salad", "image": "http://cloud.granddubai.com/broccoli/uploads/Chicken Caesar.png" }, { "id": "24", "name": "Garden Salad", "image": "http://img.ruphp.com/php/Garden.png" }, { "id": "25", "name": "Greek Salad", "image": "" }, { "id": "26", "name": "Pasta Salad", "image": "http://cloud.granddubai.com/broccoli/uploads/Pasta Salad.png" }, { "id": "27", "name": "Sunny Side up ", "image": "" }, { "id": "28", "name": "Omelette ", "image": "" }, { "id": "29", "name": "Scrambled Eggs", "image": "" }, { "id": "30", "name": "Scrambled Egg with toppings", "image": "" }, { "id": "31", "name": "Coffee", "image": "" }, { "id": "32", "name": "Fresh Juice", "image": "" }, { "id": "36", "name": "Water 500ml", "image": "" }, { "id": "35", "name": "Pepsi Can", "image": "" }, { "id": "37", "name": "Soup", "image": "" }, { "id": "38", "name": "Special Offer Family Pack", "image": "" } ] 

это мой php-файл

 <?php include ('config.php'); $id = $_GET['id']; $sql = mysqli_query($conn,"SELECT * FROM main_menu_items "); $arr = array(); $i=0; while($result = mysqli_fetch_array($sql)) { $arr[$i]['id']= $result['id']; $arr[$i]['name']= $result['name']; $arr[$i]['image']=$result['image']; $i++; } echo json_encode($arr); ?> 

это мой воображаемый человек:

 public class ImageLoader { MemoryCache memoryCache = new MemoryCache(); FileCache fileCache; private Map<ImageView, String> imageViews = Collections .synchronizedMap(new WeakHashMap<ImageView, String>()); ExecutorService executorService; // Handler to display images in UI thread Handler handler = new Handler(); public ImageLoader(Context context) { fileCache = new FileCache(context); executorService = Executors.newFixedThreadPool(5); } final int stub_id = R.drawable.nicon1; public void DisplayImage(String url, ImageView imageView) { imageViews.put(imageView, url); Bitmap bitmap = memoryCache.get(url); if (bitmap != null) imageView.setImageBitmap(bitmap); else { queuePhoto(url, imageView); imageView.setImageResource(stub_id); } } private void queuePhoto(String url, ImageView imageView) { PhotoToLoad p = new PhotoToLoad(url, imageView); executorService.submit(new PhotosLoader(p)); } private Bitmap getBitmap(String url) { File f = fileCache.getFile(url); Bitmap b = decodeFile(f); if (b != null) return b; // Download Images from the Internet try { Bitmap bitmap = null; URL imageUrl = new URL(url); HttpURLConnection conn = (HttpURLConnection) imageUrl .openConnection(); conn.setConnectTimeout(30000); conn.setReadTimeout(30000); conn.setInstanceFollowRedirects(true); InputStream is = conn.getInputStream(); OutputStream os = new FileOutputStream(f); Utils.CopyStream(is, os); os.close(); conn.disconnect(); bitmap = decodeFile(f); return bitmap; } catch (Throwable ex) { ex.printStackTrace(); if (ex instanceof OutOfMemoryError) memoryCache.clear(); return null; } } // Decodes image and scales it to reduce memory consumption private Bitmap decodeFile(File f) { try { // Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); o.inJustDecodeBounds = true; FileInputStream stream1 = new FileInputStream(f); BitmapFactory.decodeStream(stream1, null, o); stream1.close(); // Find the correct scale value. It should be the power of 2. // Recommended Size 512 final int REQUIRED_SIZE = 70; int width_tmp = o.outWidth, height_tmp = o.outHeight; int scale = 1; while (true) { if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE) break; width_tmp /= 2; height_tmp /= 2; scale *= 2; } // Decode with inSampleSize BitmapFactory.Options o2 = new BitmapFactory.Options(); o2.inSampleSize = scale; FileInputStream stream2 = new FileInputStream(f); Bitmap bitmap = BitmapFactory.decodeStream(stream2, null, o2); stream2.close(); return bitmap; } catch (FileNotFoundException e) { } catch (IOException e) { e.printStackTrace(); } return null; } // Task for the queue private class PhotoToLoad { public String url; public ImageView imageView; public PhotoToLoad(String u, ImageView i) { url = u; imageView = i; } } class PhotosLoader implements Runnable { PhotoToLoad photoToLoad; PhotosLoader(PhotoToLoad photoToLoad) { this.photoToLoad = photoToLoad; } @Override public void run() { try { if (imageViewReused(photoToLoad)) return; Bitmap bmp = getBitmap(photoToLoad.url); memoryCache.put(photoToLoad.url, bmp); if (imageViewReused(photoToLoad)) return; BitmapDisplayer bd = new BitmapDisplayer(bmp, photoToLoad); handler.post(bd); } catch (Throwable th) { th.printStackTrace(); } } } boolean imageViewReused(PhotoToLoad photoToLoad) { String tag = imageViews.get(photoToLoad.imageView); if (tag == null || !tag.equals(photoToLoad.url)) return true; return false; } // Used to display bitmap in the UI thread class BitmapDisplayer implements Runnable { Bitmap bitmap; PhotoToLoad photoToLoad; public BitmapDisplayer(Bitmap b, PhotoToLoad p) { bitmap = b; photoToLoad = p; } public void run() { if (imageViewReused(photoToLoad)) return; if (bitmap != null) photoToLoad.imageView.setImageBitmap(bitmap); else photoToLoad.imageView.setImageResource(stub_id); } } public void clearCache() { memoryCache.clear(); fileCache.clear(); } } 

вот мой адаптер Listview

 public class ListViewAdapter extends BaseAdapter { // Declare Variables Context context; LayoutInflater inflater; ArrayList<HashMap<String, String>> data; ImageLoader imageLoader; HashMap<String, String> resultp = new HashMap<String, String>(); public ListViewAdapter(Context context, ArrayList<HashMap<String, String>> arraylist) { this.context = context; data = arraylist; imageLoader = new ImageLoader(context); } @Override public int getCount() { return data.size(); } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } public View getView(final int position, View convertView, ViewGroup parent) { // Declare Variables TextView id; TextView name; TextView population; ImageView image; inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View itemView = inflater.inflate(R.layout.list_item1, parent, false); // Get the position resultp = data.get(position); // Locate the TextViews in listview_item.xml id = (TextView) itemView.findViewById(R.id.idq); name = (TextView) itemView.findViewById(R.id.type1); // Locate the ImageView in listview_item.xml image = (ImageView) itemView.findViewById(R.id.subimg); // Capture position and set results to the TextViews id.setText(resultp.get(SubMenu.RANK)); name.setText(resultp.get(SubMenu.COUNTRY)); // Capture position and set results to the ImageView // Passes flag images URL into ImageLoader.class imageLoader.DisplayImage(resultp.get(SubMenu.FLAG), image); // Capture ListView item click /**itemView.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // Get the position resultp = data.get(position); Intent intent = new Intent(context, SingleItemView.class); // Pass all data rank intent.putExtra("rank", resultp.get(MainActivity.RANK)); // Pass all data country intent.putExtra("country", resultp.get(MainActivity.COUNTRY)); // Pass all data population intent.putExtra("population",resultp.get(MainActivity.POPULATION)); // Pass all data flag intent.putExtra("flag", resultp.get(MainActivity.FLAG)); // Start SingleItemView Class context.startActivity(intent); } });*/ return itemView; } } 

Related of "Ошибка получения изображений в Listview с сервера с помощью Json"