0
我想從libs-for-android(http://code.google.com/p/libs-for-android/)中使用ImageLoader類,並且得到以下異常: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中使用?