1

有什么问题?请参阅上面的代码。

日志错误:

04-02 18:14:27.294: E/AndroidRuntime(1931): FATAL EXCEPTION: main
04-02 18:14:27.294: E/AndroidRuntime(1931): java.lang.NullPointerException
04-02 18:14:27.294: E/AndroidRuntime(1931):     at com.insidetec.itfeed.EfficientAdapter.getView(EfficientAdapter.java:89)
04-02 18:14:27.294: E/AndroidRuntime(1931):     at android.widget.AbsListView.obtainView(AbsListView.java:2159)
04-02 18:14:27.294: E/AndroidRuntime(1931):     at android.widget.ListView.makeAndAddView(ListView.java:1831)
04-02 18:14:27.294: E/AndroidRuntime(1931):     at android.widget.ListView.fillDown(ListView.java:674)
04-02 18:14:27.294: E/AndroidRuntime(1931):     at android.widget.ListView.fillFromTop(ListView.java:735)
04-02 18:14:27.294: E/AndroidRuntime(1931):     at android.widget.ListView.layoutChildren(ListView.java:1652)
04-02 18:14:27.294: E/AndroidRuntime(1931):     at android.widget.AbsListView.onLayout(AbsListView.java:1994)
04-02 18:14:27.294: E/AndroidRuntime(1931):     at 

EfficientAdapter.java(显示帖子的适配器,提取 XML):

public class EfficientAdapter extends BaseAdapter {
private Activity activity;
private ArrayList<Post> data;
private static LayoutInflater inflater = null;
//public ImageLoader imageLoader;
ViewHolder holder;

EfficientAdapter(Activity a, ArrayList<Post> d) {

    activity = a;
    data = d;
    inflater = (LayoutInflater) activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//  imageLoader = new ImageLoader(activity.getApplicationContext());

}

@Override
public int getCount() {
    return data.toArray().length;

}

@Override
public Object getItem(int position) {

    return position;
}

@Override
public long getItemId(int position) {

    return position;
}

public static class ViewHolder {
    public TextView label;
    public TextView addr;
    public ImageView image;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;

    if (convertView == null) {
        vi = inflater.inflate(R.layout.rows, null);
        holder = new ViewHolder();
        holder.label = (TextView) vi.findViewById(R.id.title);
        holder.addr = (TextView) vi.findViewById(R.id.details);
        holder.image = (ImageView) vi.findViewById(R.id.thumb);
        vi.setTag(holder);
    } else
        holder = (ViewHolder) vi.getTag();

    holder.label.setText(data.get(position).getTitle());
    holder.addr.setText(data.get(position).getPubDate());

//      imageLoader.DisplayImage((data.get(position).getThumbnail()), activity,
//              holder.image, 72, 72);
    URL url = null;
    try {
        url = new URL((data.get(position).getThumbnail()));
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    InputStream content = null;
    try {
        content = (InputStream)url.getContent();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    Drawable d = Drawable.createFromStream(content , "src"); 
    Bitmap mIcon1 = null;
     try {
         mIcon1 =
                BitmapFactory.decodeStream(url.openConnection().getInputStream());
    } catch (IOException e) {
        e.printStackTrace();
    }
    holder.image.setImageBitmap(Bitmap.createScaledBitmap(mIcon1, 72, 72, false));


    return vi;
}

我找不到日志中显示的错误!我想为我的网站创建一个 RSS 提要。

4

1 回答 1

1

这条线

holder.image.setImageBitmap(Bitmap.createScaledBitmap(mIcon1, 72, 72, false));

导致异常,因为你mIcon1null

你不能以这种方式检索你的图像

 mIcon1 =    BitmapFactory.decodeStream(url.openConnection().getInputStream());

你可能会得到 NetworkOnMainThreadException 和 NullPointerException 因为你mIcon是 null

尝试使用UniversalImageDownloader

于 2013-04-02T19:32:11.617 回答