gpt4 book ai didi

android - 如何使用 "Android-Universal-Image-Loader"

转载 作者:太空宇宙 更新时间:2023-11-03 11:51:04 25 4
gpt4 key购买 nike

我想使用 Android-Universal-Image-Loader 的 gridview 和 listview。

https://github.com/nostra13/Android-Universal-Image-Loader

我下载并修改了它。

它工作正常,但是当我更改源代码并将其移动到另一个项目时,它崩溃了。

我不知道为什么:(

没有错误和任何错误消息。

我认为是空点错误或启动库。

我认为这部分会出现错误。

    listView = (GridView) findViewById(R.id.gridview);
((GridView) listView).setAdapter(new ImageAdapter());

    public class ImageAdapter extends BaseAdapter {
@Override
public int getCount() {
Log.v("OWL","TEST1");
return imageUrls.length;
}

@Override
public Object getItem(int position) {
Log.v("OWL","TEST2");
return null;
}

@Override
public long getItemId(int position) {
Log.v("OWL","TEST3");
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.v("OWL","TEST4");
final ImageView imageView;
if (convertView == null) {
imageView = (ImageView) getLayoutInflater().inflate(R.layout.item_grid_image, parent, false);
Log.v("OWL","TEST5");
} else {
imageView = (ImageView) convertView;
Log.v("OWL","TEST6");
}

imageLoader.displayImage(imageUrls[position], imageView, options);
Log.v("OWL","TEST7");
return imageView;
}
}

我在 LOGCAT 上看不到 TEST6、TEST7

我附上日志打击。请帮助我或让我知道如何使用该库。

03-25 18:24:17.208: D/AndroidRuntime(312): Shutting down VM
03-25 18:24:17.208: W/dalvikvm(312): threadid=1: thread exiting with uncaught exception (group=0x41693438)
03-25 18:24:17.228: E/AndroidRuntime(312): FATAL EXCEPTION: main
03-25 18:24:17.228: E/AndroidRuntime(312): java.lang.IllegalStateException: ImageLoader must be init with configuration before using
03-25 18:24:17.228: E/AndroidRuntime(312): at com.nostra13.universalimageloader.core.ImageLoader.checkConfiguration(ImageLoader.java:359)
03-25 18:24:17.228: E/AndroidRuntime(312): at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:200)
03-25 18:24:17.228: E/AndroidRuntime(312): at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:162)
03-25 18:24:17.228: E/AndroidRuntime(312): at com.kmob.camera.ImageGridActivity$ImageAdapter.getView(ImageGridActivity.java:117)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.widget.AbsListView.obtainView(AbsListView.java:2449)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.widget.GridView.onMeasure(GridView.java:1030)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.View.measure(View.java:15364)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.View.measure(View.java:15364)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4824)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.View.measure(View.java:15364)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4824)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.View.measure(View.java:15364)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4824)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-25 18:24:17.228: E/AndroidRuntime(312): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2359)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.View.measure(View.java:15364)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1974)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1217)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1390)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1110)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4472)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.Choreographer.doFrame(Choreographer.java:525)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.os.Handler.handleCallback(Handler.java:615)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.os.Handler.dispatchMessage(Handler.java:92)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.os.Looper.loop(Looper.java:137)
03-25 18:24:17.228: E/AndroidRuntime(312): at android.app.ActivityThread.main(ActivityThread.java:4918)
03-25 18:24:17.228: E/AndroidRuntime(312): at java.lang.reflect.Method.invokeNative(Native Method)
03-25 18:24:17.228: E/AndroidRuntime(312): at java.lang.reflect.Method.invoke(Method.java:511)
03-25 18:24:17.228: E/AndroidRuntime(312): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
03-25 18:24:17.228: E/AndroidRuntime(312): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
03-25 18:24:17.228: E/AndroidRuntime(312): at dalvik.system.NativeStart.main(Native Method)

最佳答案

你解决了这个问题吗?您需要使用 UniversalImageLoader 上的示例代码初始化 imageLoader:

File cacheDir = StorageUtils.getCacheDirectory(context);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.memoryCacheExtraOptions(480, 800) // default = device screen dimensions
.discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75)
.taskExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
.taskExecutorForCachedImages(AsyncTask.THREAD_POOL_EXECUTOR)
.threadPoolSize(3) // default
.threadPriority(Thread.NORM_PRIORITY - 1) // default
.tasksProcessingOrder(QueueProcessingType.FIFO) // default
.denyCacheImageMultipleSizesInMemory()
.memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) // default
.memoryCacheSize(2 * 1024 * 1024)
.discCache(new UnlimitedDiscCache(cacheDir)) // default
.discCacheSize(50 * 1024 * 1024)
.discCacheFileCount(100)
.discCacheFileNameGenerator(new HashCodeFileNameGenerator()) // default
.imageDownloader(new BaseImageDownloader(context)) // default
.defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default
.enableLogging()
.build();

关于android - 如何使用 "Android-Universal-Image-Loader",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15627031/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com