我正在尝试使用libs-for-android(http://code.google.com/p/libs-for-android/)中的ImageLoader类,并且遇到以下异常:
java.lang.IllegalStateException: ImageLoader not available
579 AndroidRuntime E at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
579 AndroidRuntime E at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
579 AndroidRuntime E at android.app.ActivityThread.access$1500(ActivityThread.java:117)
579 AndroidRuntime E at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
579 AndroidRuntime E at android.os.Handler.dispatchMessage(Handler.java:99)
579 AndroidRuntime E at android.os.Looper.loop(Looper.java:123)
579 AndroidRuntime E at android.app.ActivityThread.main(ActivityThread.java:3683)
579 AndroidRuntime E at java.lang.reflect.Method.invokeNative(Native Method)
579 AndroidRuntime E at java.lang.reflect.Method.invoke(Method.java:507)
579 AndroidRuntime E at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839
)
579 AndroidRuntime E at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
579 AndroidRuntime E at dalvik.system.NativeStart.main(Native Method)
579 AndroidRuntime E Caused by: java.lang.IllegalStateException: ImageLoader not available
579 AndroidRuntime E at com.google.android.imageloader.ImageLoader.get(ImageLoader.java:103)
(上面链接的网站上有一个演示应用程序,我将跟随其作为示例:http://code.google.com/p/libs-for-android/source/browse/demos/jamendo/src/com/google/android/demos/jamendo/widget/AlbumGalleryAdapter.java)
我正在尝试使用PagerAdapter中的ImageLoader,这里是相关代码(它是导致异常的绑定语句):
public FeaturedImagePagerAdapter(Context context, ArrayList<JSONObject> images) {
this.cxt = context;
mImages = images;
mLoader = ImageLoader.get(this.cxt);
}
@Override
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) cxt
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout featured_image_layout = (LinearLayout) inflater.inflate(R.layout.featured_image_item, null);
// code omitted from this area that does some setup with the layout above.
ImageView image = (ImageView) featured_image_layout.findViewById(R.id.featured_image);
try {
mLoader.bind(image, mImages.get(position).getString("url"), null);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return featured_image_layout;
}
我没有想法 - 也许ImageLoader类不适合在PagerAdapter中使用?
答案 0 :(得分:2)
我使用ImageLoader,但我没有像那样实例化它。我这样做......
mImageLoader = new ImageLoader();