2016-09-26 54 views
1

下面我已经发布了我的应用程序类。我试图在之下将其添加到Appcontroller.java类中。不能在应用程序类中使用通用图像加载器和排除图像加载器

// UNIVERSAL IMAGE LOADER SETUP 
     DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() 
       .cacheOnDisc(true).cacheInMemory(true) 
       .imageScaleType(ImageScaleType.EXACTLY) 
       .displayer(new FadeInBitmapDisplayer(300)).build(); 

     ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
       getApplicationContext()) 
       .defaultDisplayImageOptions(defaultOptions) 
       .memoryCache(new WeakMemoryCache()) 
       .discCacheSize(100 * 1024 * 1024).build(); 

     ImageLoader.getInstance().init(config);  ------> Compile error occurred here.because of imageloader import. 

     // END - UNIVERSAL IMAGE LOADER SETUP 

但是我不能添加这个。因为在抽象图像加载器导入不同于那个通用图像加载器。

进口:

排球ImageLoader的 - 进口com.android.volley.toolbox.ImageLoader;

Universal ImageLoader -import com.nostra13.universalimageloader.core.ImageLoader;

如果我在Appcontroller中添加通用图像加载器,我得到编译错误在这一行ImageLoader.getInstance().init(config);

因为两个ImageLoader导入是不同的。

AppController中的.java:(应用程序类)

import com.android.volley.toolbox.ImageLoader; 

public class AppController extends Application { 

    private static int pendingNotificationsCount = 0; 

    public static final String TAG = AppController.class.getSimpleName(); 

    private RequestQueue mRequestQueue; 
    private ImageLoader mImageLoader; 
    LruBitmapCache mLruBitmapCache; 

    private static AppController mInstance; 

    @Override 
    public void onCreate() { 
     super.onCreate(); 

     MultiDex.install(this); 

     mInstance = this; 




    } 

    public static synchronized AppController getInstance() { 
     return mInstance; 
    } 

    public RequestQueue getRequestQueue() { 
     if (mRequestQueue == null) { 
      mRequestQueue = Volley.newRequestQueue(getApplicationContext()); 
     } 

     return mRequestQueue; 
    } 

    public ImageLoader getImageLoader() { 
     getRequestQueue(); 
     if (mImageLoader == null) { 
      getLruBitmapCache(); 
      mImageLoader = new ImageLoader(this.mRequestQueue, mLruBitmapCache); 
     } 

     return this.mImageLoader; 
    } 

    public LruBitmapCache getLruBitmapCache() { 
     if (mLruBitmapCache == null) 
      mLruBitmapCache = new LruBitmapCache(); 
     return this.mLruBitmapCache; 
    } 

    public void addToRequestQueue(Request<String> req, String tag) { 
     req.setTag(TextUtils.isEmpty(tag) ? TAG : tag); 
     req.setShouldCache(false); 
     getRequestQueue().add(req); 
    } 

    public void addToRequestQueue(JsonObjectRequest req) { 
     req.setTag(TAG); 
     getRequestQueue().add(req); 
    } 

    public void cancelPendingRequests(Object tag) { 
     if (mRequestQueue != null) { 
      mRequestQueue.cancelAll(tag); 
     } 
    } 


    public static int getPendingNotificationsCount() { 
     return pendingNotificationsCount; 
    } 

    public static void setPendingNotificationsCount(int pendingNotifications) { 
     pendingNotificationsCount = pendingNotifications; 
    } 

} 
+0

为什么你不能?你为什么不告诉? – greenapps

+0

@greenapps编辑post.please检查 – Steve

+0

'我越来越编译错误'任何理由不提及确切的错误?你让我们猜测。为什么? – greenapps

回答

2

你的问题不是来自同时使用UIL和Volley,而是从不同库中使用2个具有相同名称的类。

您可以使用全限定名称,如com.package.path.ImageLoader而不是import来解决该问题。

您也可以看看这个问题:Importing two classes with same name. How to handle?

更新与演示代码

而不是

// UNIVERSAL IMAGE LOADER SETUP 
    DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() 
      .cacheOnDisc(true).cacheInMemory(true) 
      .imageScaleType(ImageScaleType.EXACTLY) 
      .displayer(new FadeInBitmapDisplayer(300)).build(); 

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
      getApplicationContext()) 
      .defaultDisplayImageOptions(defaultOptions) 
      .memoryCache(new WeakMemoryCache()) 
      .discCacheSize(100 * 1024 * 1024).build(); 

    ImageLoader.getInstance().init(config);  ------> Compile error occurred here.because of imageloader import. 

    // END - UNIVERSAL IMAGE LOADER SETUP 

删除或者ImageLoaderimport,并更改代码:

// UNIVERSAL IMAGE LOADER SETUP 
    DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() 
      .cacheOnDisc(true).cacheInMemory(true) 
      .imageScaleType(ImageScaleType.EXACTLY) 
      .displayer(new FadeInBitmapDisplayer(300)).build(); 

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
      getApplicationContext()) 
      .defaultDisplayImageOptions(defaultOptions) 
      .memoryCache(new WeakMemoryCache()) 
      .discCacheSize(100 * 1024 * 1024).build(); 

      com.nostra13.universalimageloader.core.ImageLoader.getInstance().init(config);  ------> Compile error occurred here.because of imageloader import. 

    // END - UNIVERSAL IMAGE LOADER SETUP 
1

您可以删除的进口和使用com.android.volley.toolbox.ImageLoadercom.nostra13.universalimageloader.core.ImageLoader代替ImageLoader的的代码。

相关问题