@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
if(convertView == null)
{
convertView = inflater.inflate(R.layout.photodata,null);
myHolder = new ViewHolder();
try
{
myHolder.imgPhoto = (ImageView) convertView.findViewById(R.id.imgPhoto);
}
catch (Exception e)
{
e.printStackTrace();
}
convertView.setTag(myHolder);
}
else
{
myHolder = (ViewHolder)convertView.getTag();
}
System.out.println("String image is" + getItem(position).photo);
myHolder.imgPhoto.setTag(getItem(position).photo);
System.out.println("String image is" + getItem(position).photo);
imageLoader.DisplayImage(getItem(position).photo,activity, myHolder.imgPhoto);
return convertView;
}
錯誤:的Java空指針異常
FATAL EXCEPTION: main
java.lang.NullPointerException
at.com.android.adapter.PhotoAdater.getView(PhotoAdater.java:59)
at.android.widget.AbsListView.obtainView(AbsListView.java:1315)
59代表(我相信)的行號引發異常。它應該確定哪些變量是候選者爲空。您也可以嘗試調試並在其中放置斷點,以驗證爲什麼它可能爲空。 – aardvarkk
在'ViewHolder持有人'中是否有拼寫錯誤,認爲該變量必須是'myHolder' – Balanivash