2

我正在尝试在我的 monodroid 项目中添加这个 Android 库( https://github.com/nostra13/Android-Universal-Image-Loader )。在 Visual Studio 2010 中,我创建了一个Java 绑定库项目,在其中添加了该库的jar文件。

问题是,当我构建我的项目时,我遇到了一些错误:

'Com.Nostra13.Universalimageloader.Cache.Memory.Impl.LRULimitedMemoryCache.RemoveNext()': return type must be 'Java.Lang.Object' to match overridden member 'Com.Nostra13.Universalimageloader.Cache.Memory.LimitedMemoryCache.RemoveNext()'

在构建自动生成的这段代码上

    static IntPtr id_removeNext;
    [Register ("removeNext", "()Landroid/graphics/Bitmap;", "GetRemoveNextHandler")]
    protected override global::Android.Graphics.Bitmap RemoveNext ()
    {
        if (id_removeNext == IntPtr.Zero)
            id_removeNext = JNIEnv.GetMethodID (class_ref, "removeNext", "()Landroid/graphics/Bitmap;");

        if (GetType () == ThresholdType)
            return Java.Lang.Object.GetObject<global::Android.Graphics.Bitmap> (JNIEnv.CallObjectMethod  (Handle, id_removeNext), JniHandleOwnership.TransferLocalRef);
        else
            return Java.Lang.Object.GetObject<global::Android.Graphics.Bitmap> (JNIEnv.CallNonvirtualObjectMethod  (Handle, ThresholdClass, id_removeNext), JniHandleOwnership.TransferLocalRef);
    }   

还有这个错误

'Com.Nostra13.Universalimageloader.Core.Download.URLConnectionImageDownloader' does not implement inherited abstract member 'Com.Nostra13.Universalimageloader.Core.Download.ImageDownloader.GetStreamFromNetwork(Java.Net.URI)'    

在这行代码上

 public partial class URLConnectionImageDownloader : global::Com.Nostra13.Universalimageloader.Core.Download.ImageDownloader

有谁知道如何解决这个问题?或者有没有人在他们的 Monodroid 应用程序中成功导入了这个 java 库?

任何帮助深表感谢。谢谢

4

2 回答 2

4

将此添加到您的 Transforms\Metadata.xml 文件中

<attr path=”/api/package[@name=’com.nostra13.universalimageloader.cache.memory.impl’]
/class[@name=’LRULimitedMemoryCache’]
/method[@name=’removeNext’]” name=”managedReturn”&gt;Java.Lang.Object</attr>

对于第二个错误,您可以添加实现该方法的部分类定义GetStreamFromNetwork(Java.Net.URI)

namespace Com.Nostra13.Universalimageloader.Core.Download {
   partial class URLConnectionImageDownloader{
       public override InputStream GetStreamFromNetwork(Java.Net.URI) {
           return null;
       }
   }
}

请阅读本教程以获取更多信息

于 2012-11-13T11:42:38.717 回答
2

万一有人正在寻找有效的绑定(从 Universal Image Loader 1.8.4v 开始)。

Transforms\Metadata.xml:

<metadata>
  <!-- Binding to universal-image-loader-1.8.4.jar -->
  <!-- We are changing the return types to eliminate errors like 'return type must be 'Java.Lang.Object' to match overridden member' -->
  <attr path="/api/package[@name='com.nostra13.universalimageloader.cache.memory.impl']/class[@name='FIFOLimitedMemoryCache']/method[@name='removeNext']" name="managedReturn">Java.Lang.Object</attr>
  <attr path="/api/package[@name='com.nostra13.universalimageloader.cache.memory.impl']/class[@name='LargestLimitedMemoryCache']/method[@name='removeNext']" name="managedReturn">Java.Lang.Object</attr>
  <attr path="/api/package[@name='com.nostra13.universalimageloader.cache.memory.impl']/class[@name='LRULimitedMemoryCache']/method[@name='removeNext']" name="managedReturn">Java.Lang.Object</attr>
  <attr path="/api/package[@name='com.nostra13.universalimageloader.cache.memory.impl']/class[@name='UsingFreqLimitedMemoryCache']/method[@name='removeNext']" name="managedReturn">Java.Lang.Object</attr>
</metadata>

以及一组部分类(例如放置在 Additions/Fixes.cs 中):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;

// Fixes to get rid of "does not implement inherited abstract member" errors

namespace Com.Nostra13.Universalimageloader.Cache.Memory.Impl
{
    partial class FIFOLimitedMemoryCache
    {
        protected override int GetSize(Java.Lang.Object value)
        {
            return GetSize(value);
        }

        protected override Java.Lang.Ref.Reference CreateReference(Java.Lang.Object value)
        {
            return CreateReference(value);
        }
    }

    partial class LargestLimitedMemoryCache
    {
        protected override int GetSize(Java.Lang.Object value)
        {
            return GetSize(value);
        }

        protected override Java.Lang.Ref.Reference CreateReference(Java.Lang.Object value)
        {
            return CreateReference(value);
        }
    }

    partial class LRULimitedMemoryCache
    {
        protected override int GetSize(Java.Lang.Object value)
        {
            return GetSize(value);
        }

        protected override Java.Lang.Ref.Reference CreateReference(Java.Lang.Object value)
        {
            return CreateReference(value);
        }
    }

    partial class UsingFreqLimitedMemoryCache
    {
        protected override int GetSize(Java.Lang.Object value)
        {
            return GetSize(value);
        }

        protected override Java.Lang.Ref.Reference CreateReference(Java.Lang.Object value)
        {
            return CreateReference(value);
        }
    }

    partial class WeakMemoryCache
    {
        protected override Java.Lang.Ref.Reference CreateReference(Java.Lang.Object value)
        {
            return CreateReference(value);
        }
    }

    // Fixing ther error 'Com.Nostra13.Universalimageloader.Cache.Memory.Impl.LruMemoryCache' does not implement interface member 'Com.Nostra13.Universalimageloader.Cache.Memory.IMemoryCacheAware.Keys()'. 'Com.Nostra13.Universalimageloader.Cache.Memory.Impl.LruMemoryCache.Keys()' 
    // cannot implement 'Com.Nostra13.Universalimageloader.Cache.Memory.IMemoryCacheAware.Keys()' because it does not have the matching return type of 'System.Collections.ICollection'. -->

    partial class LruMemoryCache
    {
        System.Collections.ICollection Com.Nostra13.Universalimageloader.Cache.Memory.IMemoryCacheAware.Keys()
        {
            return (System.Collections.ICollection)Keys();
        }
    }
}

namespace Com.Nostra13.Universalimageloader.Core.Assist.Deque
{
    partial class LinkedBlockingDeque
    {
        partial class DescendingItr
        {
            public override Java.Lang.Object Next()
            {
                return Next();
            }
        };

        partial class Itr
        {
            public override Java.Lang.Object Next()
            {
                return Next();
            }
        }
    }
}
于 2013-05-18T09:59:07.273 回答