Android: Nullpointer Exception Error in Activity

你。 提交于 2020-01-25 09:45:10

问题


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;

    }

since this is for a listview, it shows both images and text. In the other hand I have an activity, where I want to apply the imageLoader.DisplayImage method in it only to show images.

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);
    }

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


回答1:


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



来源:https://stackoverflow.com/questions/5911934/android-nullpointer-exception-error-in-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!