gpt4 book ai didi

java - SkImageDecoder::Factory 返回 null 并且 URL 正确

转载 作者:太空宇宙 更新时间:2023-11-04 12:28:42 24 4
gpt4 key购买 nike

我试图将来自 URL 的图像放入 ImageView 中,但我不断收到“SkImageDecoder::Factory returned null”错误。

这是我的代码:

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;

public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}

protected Bitmap doInBackground(String... urls) {
String myUrl= urls[0];

Bitmap myBmp= null;
try {
InputStream in = new URL(urldisplay).openStream();
myBmp= BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return myBmp;
}

protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}

编辑: logcat 当应用程序在获取第一张图像后崩溃时 logcat

public class customAdapter extends ArrayAdapter<String> {
private final Context context;
private final ArrayList<String> values;

static class ViewHolder {

private TextView textViewName;
private TextView textViewType;
private ImageView imageView;
}

public customAdapter(Context context, ArrayList<String> values) {
super(context, R.layout.list_member, values);
this.context = context;
this.values = values;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder mViewHolder = null;
if (convertView == null) {
mViewHolder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_member, parent, false);
mViewHolder.textViewName = (TextView) convertView.findViewById(R.id.name);
mViewHolder.textViewType = (TextView) convertView.findViewById(R.id.type);
mViewHolder.imageView = (ImageView) convertView.findViewById(R.id.image);

convertView.setTag(mViewHolder);
}
else {
mViewHolder = (ViewHolder) convertView.getTag();
}
String s = values.get(position);
StringTokenizer st = new StringTokenizer(s, "*");
String name = st.nextToken();
String url_photo = st.nextToken();
String type = st.nextToken();
if (type.equals("CHILD")) {
String count_dev = st.nextToken();
mViewHolder.textViewType.setText(count_dev);
}
else {
mViewHolder.textViewType.setText(type);
}
mViewHolder.textViewName.setText(name);
new DownloadImageTask(mViewHolder.imageView).execute(url_photo);
return convertView;
}

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;

public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}

protected Bitmap doInBackground(String... urls) {
// TODO Auto-generated method stub
String urlStr = urls[0];
Bitmap img = null;

HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(urlStr);
HttpResponse response;
try {
response = (HttpResponse)client.execute(request);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(entity);
InputStream inputStream = bufferedEntity.getContent();
img = BitmapFactory.decodeStream(inputStream);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return img;
}

protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
}

根据要求,这是此类的完整代码

最佳答案

尝试在后台方法中添加此代码:

   protected Bitmap doInBackground(String... params) {
// TODO Auto-generated method stub
String urlStr = params[0];
Bitmap img = null;

HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(urlStr);
HttpResponse response;
try {
response = (HttpResponse)client.execute(request);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(entity);
InputStream inputStream = bufferedEntity.getContent();
img = BitmapFactory.decodeStream(inputStream);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return img;
}

关于java - SkImageDecoder::Factory 返回 null 并且 URL 正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38107075/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com