安卓:在活动空指针异常错误 [英] Android: Nullpointer Exception Error in Activity

查看:180
本文介绍了安卓:在活动空指针异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的ListViewAdapter这里面getView方法:

I have this getView method inside my ListViewAdapter:

public static class ViewHolder{
        public TextView textTitle;
        public ImageView image;
    }

  public View getView(int position, View convertView, ViewGroup parent)
    {
        Project pro = getItem(position);

        View vi=convertView;
        ViewHolder holder;
        if(convertView==null){
            vi = inflater.inflate(R.layout.listitems, null);
            holder=new ViewHolder();
            holder.textTitle=(TextView)vi.findViewById(R.id.txt_title);;
            holder.image=(ImageView)vi.findViewById(R.id.image);
            vi.setTag(holder);
        }
        else
        holder=(ViewHolder)vi.getTag();
        holder.textTitle.setText(pro.project_title);
        holder.image.setTag(pro);
        imageLoader.DisplayImage(pro.smallImageUrl, activity, holder.image);
        return vi;

    }

,因为这是一个列表视图,它显示图像和文本。
在另一方面,我有一个活动,在这里我想申请的 imageLoader.DisplayImage 方法,仅显示图像。

根据ListView控件适配器,我做了这个活动里面的:

Based on the ListView Adapter, I made this inside an activity:

imageLazy(image1, Main.this, prjcts.get(randomIndex1));

public void imageLazy(final ImageView image, Activity activity, Project pro)
    {
    imageLoaderx.DisplayImage(pro.smallImageUrl, activity, image);
    }

但后来我的应用程序崩溃。该报告logcat中一个空指针异常错误和一个错误与我imageLazy方法。

But then my app crashed. The Logcat reports a Nullpointer Exception Error and an error with my imageLazy method.

任何人可以帮助我解决我的问题呢?所以,我的方法可以显示没有错误的图像?
非常感谢你。

Can anybody help me to solve my problem? So that my method can display the images without error? Thank you very much

推荐答案

imageLoaderX尚未初始化和为空。你可以通过创建一个新的对象或其他地方得到一个非空引用解决这个问题。

imageLoaderX has not been initialized and is null. You can fix this by creating a new object or getting a non null reference elsewhere.

这篇关于安卓:在活动空指针异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆