0

你好,我正在尝试学习 json 解析并我解决了一些问题,但我有问题我可以在我的列表视图中获取信息,但我无法拍照,我的日志说

我的代码在这里我更改 url 和一些字符串如何解析 Sub JSONArray 并显示图像?

请帮助我已经谢谢....

04-02 07:59:27.767: W/System.err(1737): java.net.MalformedURLException: Protocol not found: WOW1079.jpg
04-02 07:59:27.815: W/System.err(1737):     at java.net.URL.<init>(URL.java:178)
04-02 07:59:27.945: W/System.err(1737):     at java.net.URL.<init>(URL.java:127)
04-02 07:59:28.095: W/System.err(1737):     at com.example.benm.DownloadImageTask.getBitmap(DownloadImageTask.java:41)
04-02 07:59:28.315: W/System.err(1737):     at com.example.benm.DownloadImageTask.doInBackground(DownloadImageTask.java:34)
04-02 07:59:28.465: W/System.err(1737):     at com.example.benm.DownloadImageTask.doInBackground(DownloadImageTask.java:1)
04-02 07:59:28.695: W/System.err(1737):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
04-02 07:59:28.875: W/System.err(1737):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-02 07:59:28.885: W/System.err(1737):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-02 07:59:28.895: W/System.err(1737):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
04-02 07:59:28.907: W/System.err(1737):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
04-02 07:59:28.915: W/System.err(1737):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
04-02 07:59:28.925: W/System.err(1737):     at java.lang.Thread.run(Thread.java:856)
04-02 07:59:28.995: W/System.err(1737): java.net.MalformedURLException: Protocol not found: WOW749.jpg
04-02 07:59:29.036: W/System.err(1737):     at java.net.URL.<init>(URL.java:178)
04-02 07:59:29.045: W/System.err(1737):     at java.net.URL.<init>(URL.java:127)
04-02 07:59:29.055: W/System.err(1737):     at com.example.benm.DownloadImageTask.getBitmap(DownloadImageTask.java:41)
04-02 07:59:29.066: W/System.err(1737):     at com.example.benm.DownloadImageTask.doInBackground(DownloadImageTask.java:34)
04-02 07:59:29.095: W/System.err(1737):     at com.example.benm.DownloadImageTask.doInBackground(DownloadImageTask.java:1)
04-02 07:59:29.155: W/System.err(1737):     at android.os.AsyncTask$2.call(AsyncTask.java:264)
04-02 07:59:29.165: W/System.err(1737):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
04-02 07:59:29.175: W/System.err(1737):     at java.util.concurrent.FutureTask.run(FutureTask.java:137)
04-02 07:59:29.185: W/System.err(1737):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)

here is my code

公共类 DownloadImageTask 扩展 AsyncTask {

private String mUrl;
private ImageView mImageView = null;

public DownloadImageTask(String Url, ImageView imageView) {

    mUrl = Url;
    this.mImageView = imageView;
}

protected void onPostExecute(Bitmap result) {
    super.onPostExecute(result);
    if (result != null) {
        mImageView.setImageBitmap(result);
    }
}

protected Bitmap doInBackground(Void... params) {

    Bitmap bitmap = getBitmap(mUrl);
    return bitmap;
}

public Bitmap getBitmap(String imageUrl) {
    Bitmap mBitmap = null;
    try {
        URL url = new URL(imageUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        InputStream is = conn.getInputStream();
        mBitmap = BitmapFactory.decodeStream(is);

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return mBitmap;
}

}

4

1 回答 1

0

根据给定 logcat 中描述的 MalformedURLException,我可以说URL is not valid。只需检查图像 URL 值WOW749.jpg作为响应,您不会获得完整的图像名称,而只是图像的名称。

所以我建议你在调用getBitmap()函数时嵌入带有图像名称的 webservice URL,它会解决你的问题。

于 2013-04-02T13:17:20.980 回答