0

所以我已经坚持了几个小时。我正在尝试设置一个异步任务,该任务将在另一个类中为我的列表视图加载图像,并且我正在传递给我错误的信息

任何帮助,将不胜感激!

公共类 TheResults 扩展 Activity {

public static final String DEFAULTNAME = "DefaultFile";
private GETTHEIMAGE imgFetch;
private ArrayList<Item_Info> Info = new ArrayList<Item_Info>();

String Data = null;
String THESTRING = null;
TextView httpStuff;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // full screen
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.theresults);

    SharedPreferences Search = getSharedPreferences(DEFAULTNAME, 0);
    Data = Search.getString("THERESULTS", null);
    GetINFO();
    populatelist();
}

private void GetINFO() {
    }
    }
}

private void populatelist() {
    ArrayAdapter<Item_Info> adapter = new TheListAdapter();
    ListView list = (ListView) findViewById(R.id.listings);
    list.findFocus();
    list.getWindowToken();
    list.setAdapter(adapter);
}

public class TheListAdapter extends ArrayAdapter<Item_Info> {
    public TheListAdapter() {
        super(TheResults.this, R.layout.items, Info);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View item_View = convertView;
        ImageHolder holder = null;

        if (item_View == null) {
            item_View = getLayoutInflater().inflate(R.layout.items, parent, false);
            Item_Info CurrentItem = Info.get(position);
            holder = new ImageHolder();
            holder.ICON_IMG = (ImageView)item_View.findViewById(R.id.icon_image);
            holder.ICON_IMG.setTag(CurrentItem.getItemPIC());
            Drawable MYIMG = imgFetch.GetTheImagedata(this, holder.ICON_IMG);

            holder.ICON_TITLE = (TextView)item_View.findViewById(R.id.icon_title);
            holder.ICON_TITLE.setText(CurrentItem.getItemTITLE());

            holder.ICON_LOCATION = (TextView)item_View.findViewById(R.id.icon_location);
            holder.ICON_LOCATION.setText(CurrentItem.getItemLOCATION());

            holder.ICON_PRICE = (TextView)item_View.findViewById(R.id.icon_price);
            if (CurrentItem.getItemPRICE() == null) {
                holder.ICON_PRICE.setText(CurrentItem.getItemPRICE());
                holder.ICON_PRICE.setBackgroundResource(R.drawable.tempbg);
            } else {
                holder.ICON_PRICE.setBackgroundResource(R.drawable.pricebg);
                holder.ICON_PRICE.setText(CurrentItem.getItemPRICE());
            }

            holder.ICON_DATE = (TextView)item_View.findViewById(R.id.icon_date);
            holder.ICON_DATE.setText(CurrentItem.getItemLOCATION());
        }else{
            holder = (ImageHolder)item_View.getTag();
        }
        return item_View;
    }
}
static class ImageHolder{
    ImageView ICON_IMG;
    TextView ICON_TITLE;
    TextView ICON_LOCATION;
    TextView ICON_PRICE;
    TextView ICON_DATE;
}

}

4

1 回答 1

0

通过查看行后的 logcat

06-21 19:15:06.887: E/AndroidRuntime(11408): FATAL EXCEPTION: main

是例外

java.lang.NullPointerException

它告诉我们某事是null并且正在抛出异常。如果我们查找引用您的项目的代码的第一行,我们将看到问题发生在哪里。在这里,它恰好是 logcat 中的下一行

at com.clistc.TheResults$TheListAdapter.getView(TheResults.java:178)

这告诉我们该行是第 178 行TheResults.java并且它在getView()方法内部。我们已经确定是这条线

Drawable MYIMG = imgFetch.GetTheImagedata(this, holder.ICON_IMG); 

这意味着这imgFetch可能是null并且您尝试在其上调用一个函数,该函数返回,null因为变量是null. 我不知道那个变量是什么,但在这一行之前它没有被初始化

编辑

imgFetch没有在任何地方初始化。在这里声明

private GETTHEIMAGE imgFetch;

但是你永远不会通过给它一个值来初始化它。你需要做类似的事情

private GETTHEIMAGE imgFetch = new GETTHEIMAGE();

假设它有一个空的构造函数

于 2013-06-21T23:27:29.180 回答