Question

I have implemented a Custom ListView using LazyAdapter to display thumbnail images. Finally after I got this LazyAdapter working, the OnItemClickListener doesn't display the data and simply returns the empty strings. The code is working fine if I remove the Custom LazyAdapter class for the ListView.

    class LoadAllDirectories extends AsyncTask<String, String, String> {

        protected String doInBackground(String... args) {

            UserFunctions fn = new UserFunctions();
            String id = fn.getID(getApplicationContext());

            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("id", id));

            JSONObject json = 
            jParser.makeHttpRequest(url_all_directories, "GET", params);

            Log.d("All Directories: ", json.toString());

            try {

                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {

                    directories = json.getJSONArray(TAG_DIRECTORIES);

                    for (int i = 0; i < directories.length(); i++) {
                        JSONObject c = directories.getJSONObject(i);

                        String eid = c.getString(TAG_ID);
                        String name = c.getString(TAG_NAME);                        
                        String image = c.getString(TAG_IMG);

                        HashMap<String, String> map = 
                        new HashMap<String, String>();

                        map.put(TAG_ID, eid);
                        map.put(TAG_NAME, name);                        
                        map.put(TAG_IMG, image);

                        directoryList.add(map);
                    }

                } else {

                    Intent i = new Intent(getApplicationContext(),
                            DirectoryActivity.class);

                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        protected void onPostExecute(String file_url) {

            runOnUiThread(new Runnable() {
                public void run() {

                    ListAdapter adapter = new LazyAdapter(
                    DirectoryAllActivity.this, directoryList);                  
                    setListAdapter(adapter);
                }
            });

        }

    }

}

ErrorLog

update: part of the duplicated Log was deleted.

11-19 14:17:12.612: W/System.err(16343): java.net.MalformedURLException: Protocol not found: null
11-19 14:17:12.612: W/System.err(16343):    at java.net.URL.<init>(URL.java:178)
11-19 14:17:12.612: W/System.err(16343):    at java.net.URL.<init>(URL.java:127)
11-19 14:17:12.612: W/System.err(16343):    at com.app.android.library.ImageLoader.getBitmap(ImageLoader.java:70)
11-19 14:17:12.612: W/System.err(16343):    at com.app.android.library.ImageLoader.access$0(ImageLoader.java:58)
11-19 14:17:12.612: W/System.err(16343):    at com.app.android.library.ImageLoader$PhotosLoader.run(ImageLoader.java:135)
11-19 14:17:12.612: W/System.err(16343):    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
11-19 14:17:12.622: W/System.err(16343):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-19 14:17:12.622: W/System.err(16343):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-19 14:17:12.622: W/System.err(16343):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-19 14:17:12.622: W/System.err(16343):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-19 14:17:12.622: W/System.err(16343):    at java.lang.Thread.run(Thread.java:856)
11-19 14:17:12.653: D/memalloc(16343): ion: Mapped buffer base:0x5e951000 size:3768320 offset:0 fd:55
Was it helpful?

Solution

Caused By: java.net.MalformedURLException

You need to use a real URL, not this:

private static String url_all_directories = "a_web_url";

You can start with the tutorial's suggested URL: http://api.androidhive.info/music/music.xml


Hey! You sneakily changed your LogCat.

Anyway, now the problem is an image URL:

at com.app.android.library.ImageLoader.getBitmap(ImageLoader.java:70) 

Check the data at "a_web_url", which is apparently on a server of yours...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top