Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

nullpointerexception - Android: Nullpointer Exception Error in Activity

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...