如何将Drawable转换为int

时间:2016-12-08 04:55:47

标签: java android int inputstream android-drawable

java.lang.NumberFormatException: Invalid int: "android.graphics.drawable.BitmapDrawable

int LoadImageFromWebOperations(String url) {
        try {
            InputStream is = (InputStream) new URL(url).getContent();
            Drawable d = Drawable.createFromStream(is, null);
            return Integer.parseInt(d.toString());//getting error at this line


        } catch (Exception e) {
            return R.mipmap.ic_launcher;
        }
    }

从JSON获取数据

 try {
                JSONObject jsonObj = new JSONObject(jsonStr);
                JSONArray data;
                // Getting JSON Array node
                data = jsonObj.getJSONArray("data");

                // looping through All Contacts
                for (int i = 0; i < data.length() - 1; i++) {

                    ListData ld = new ListData();
                    JSONObject c = data.getJSONObject(i);

ld.setImages(LoadImageFromWebOperations(c.getString("photo_url")));// calling ListaData method to set Image 

                    myList.add(ld);
  }
            } catch (final JSONException e) {
                Log.e(TAG, "Json parsing error: " + e.getMessage());
                getActivity().runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getActivity(),
                                "Json parsing error: " + e.getMessage(),
                                Toast.LENGTH_LONG)
                                .show();
                    }
                });

            }

这里是ListData模型类方法

public int getImages() {
    return Images;
}

public void setImages(int images) {
    Images = images;
}

我要做的是从ListData Model类中获取JSON数据,然后使用SetImage(int image)方法设置图像。

0 个答案:

没有答案