我在LayoutInflator中遇到NullPointerException。我想做导航滑块菜单,但我有一个错误。你能救我吗?
public class CategoryAdapter extends BaseAdapter {
private FragmentActivity nav_slider_activity;
private LayoutInflater nav_slider_inflater;
private List<Movie> nav_slider_movieitems;
public CategoryAdapter(FragmentActivity nav_slider_activity, List<Movie> items){
this.nav_slider_activity = nav_slider_activity;
this.nav_slider_movieitems = items;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return nav_slider_movieitems.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return nav_slider_movieitems.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (nav_slider_inflater == null)
nav_slider_inflater = (LayoutInflater) nav_slider_activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(convertView==null)
convertView = nav_slider_inflater.inflate(R.layout.navigation_slider_list_layout, parent, false);
if (nav_slider_imageLoader == null)
nav_slider_imageLoader= AppData.getInstance().getImageLoader();
NetworkImageView image = (NetworkImageView) convertView
.findViewById(R.id.nav_slider_view);
TextView nav_slider_title = (TextView) convertView.findViewById(R.id.nav_slider_header);
image.buildDrawingCache();
final Bitmap nav_slider_bitmap = image.getDrawingCache();
image.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Bundle nav_slider_bundle = new Bundle();
nav_slider_bundle.putParcelable("Nav_slider_image", nav_slider_bitmap);
Movie nav_slider_product = nav_slider_movieitems.get(position);
nav_slider_bundle.putParcelable("Navslidertitle", nav_slider_product);
Intent intent = new Intent(nav_slider_activity, Category_Detail.class);
intent.putExtras(nav_slider_bundle);
nav_slider_activity.startActivity(intent);
return false;
}
});
Movie m = nav_slider_movieitems.get(position);
image.setImageUrl(m.getThumbnailUrl(), nav_slider_imageLoader);
nav_slider_title.setText(m.getTitle());
return convertView;
}
}
它抛出了这个错误..
FATAL EXCEPTION: main
java.lang.NullPointerException
at com.navslider.category.CategoryAdapter.getView(CategoryAdapter.java:61)
at android.widget.AbsListView.obtainView(AbsListView.java:2177)
at android.widget.ListView.makeAndAddView(ListView.java:1840)
...