ImageLoader ライブラリを使用して ViewPager を作成しましたが、このコードにエラーがあり、ログで彼が何を望んでいるのかわかりません! メイン レイアウトでは、adapterLayout には ViewPager のみがあり、FrameLayout には ImageView があります。
public class ImageGallery extends Activity {
ViewPager pager;
String[] BigImages;
String[] Authors;
String[] Dates;
String[] Descriptions;
DisplayImageOptions options;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Bundle bundle = getIntent().getExtras();
String[] imageUrls = bundle.getStringArray("big_images");
int pagerPosition = bundle.getInt("position");
options = new DisplayImageOptions.Builder()
.showImageForEmptyUri(R.drawable.ic_contact_picture_2)
.resetViewBeforeLoading()
.cacheOnDisc()
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.bitmapConfig(Bitmap.Config.RGB_565)
.displayer(new FadeInBitmapDisplayer(300))
.build();
ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(new GalleryImage(ImageGallery.this, imageUrls));
pager.setCurrentItem(pagerPosition);
}
class GalleryImage extends PagerAdapter{
private String[] images;
private LayoutInflater inflater;
ImageLoader imageLoader;
GalleryImage(Context context, String[] images) {
this.images = images;
inflater = getLayoutInflater();
imageLoader = ImageLoader.getInstance();
imageLoader.init(ImageLoaderConfiguration.createDefault(context));
}
@Override
public void destroyItem(View container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
@Override
public int getCount() {
return images.length;
}
@Override
public Object instantiateItem(View view, int position) {
final View imageLayout = inflater.inflate(R.layout.item_gallery, null);
final ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);
imageLoader.displayImage(images[position], imageView, options);
((ViewPager) view).addView(imageLayout, 0);
return imageLayout;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view.equals(object);
}
}}
ログ
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gazetaimage/com.gazetaimage.ImageGallery}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2356)
at android.app.ActivityThread.access$600(ActivityThread.java:150)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5193)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.gazetaimage.ImageGallery.onCreate(ImageGallery.java:49)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260)
... 11 more