我希望在我的Android项目中使用Apache Commons VFS库,并从http://commons.apache.org/vfs/download_vfs.cgi.然而我遇到了一些问题。
我已经将commons-vfs2-2.0.jar文件复制到我的android项目的/libs/子目录中,并在Eclipse中的java构建路径中引用了它。我还参考了Commons VFS使用的Commons日志库(http://commons.apache.org/vfs/download.html)。
一切都编译得很好,但只要我尝试以下代码行
FileSystemManager fsManager = VFS.getManager();
我有个例外。这是堆栈跟踪:
02-06 16:22:29.724: ERROR/Fatal Error(20515): Could not create a file system manager of class "org.apache.commons.vfs2.impl.StandardFileSystemManager".
02-06 16:22:29.724: ERROR/Fatal Error(20515): org.apache.commons.vfs2.FileSystemException: Could not create a file system manager of class "org.apache.commons.vfs2.impl.StandardFileSystemManager".
02-06 16:22:29.724: ERROR/Fatal Error(20515): at org.apache.commons.vfs2.VFS.createManager(VFS.java:99)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at org.apache.commons.vfs2.VFS.getManager(VFS.java:50)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at gymApp.gymAppPackage.Utility.test(Utility.java:391)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at gymApp.gymAppPackage.HomeActivity.onCreate(HomeActivity.java:51)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2466)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2519)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at android.app.ActivityThread.access$2200(ActivityThread.java:123)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1870)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at android.os.Handler.dispatchMessage(Handler.java:99)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at android.os.Looper.loop(Looper.java:123)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at android.app.ActivityThread.main(ActivityThread.java:4370)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at java.lang.reflect.Method.invokeNative(Native Method)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at java.lang.reflect.Method.invoke(Method.java:521)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at dalvik.system.NativeStart.main(Native Method)
02-06 16:22:29.724: ERROR/Fatal Error(20515): Caused by: org.apache.commons.vfs2.FileSystemException: Could not load VFS configuration from "jar:file:/data/app/gymApp.gymAppPackage.apk!/org/apache/commons/vfs2/impl/providers.xml".
02-06 16:22:29.724: ERROR/Fatal Error(20515): at org.apache.commons.vfs2.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:199)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at org.apache.commons.vfs2.impl.StandardFileSystemManager.init(StandardFileSystemManager.java:123)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at java.lang.reflect.Method.invokeNative(Native Method)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at java.lang.reflect.Method.invoke(Method.java:521)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at org.apache.commons.vfs2.VFS.createManager(VFS.java:88)
02-06 16:22:29.724: ERROR/Fatal Error(20515): ... 16 more
02-06 16:22:29.724: ERROR/Fatal Error(20515): Caused by: org.apache.commons.vfs2.FileSystemException: Could not create file provider of class "org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider".
02-06 16:22:29.724: ERROR/Fatal Error(20515): at org.apache.commons.vfs2.impl.StandardFileSystemManager.createInstance(StandardFileSystemManager.java:490)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at org.apache.commons.vfs2.impl.StandardFileSystemManager.addProvider(StandardFileSystemManager.java:371)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at org.apache.commons.vfs2.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:270)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at org.apache.commons.vfs2.impl.StandardFileSystemManager.configure(StandardFileSystemManager.java:195)
02-06 16:22:29.724: ERROR/Fatal Error(20515): ... 20 more
02-06 16:22:29.724: ERROR/Fatal Error(20515): Caused by: java.lang.ClassNotFoundException: org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider in loader dalvik.system.PathClassLoader@400264d8
02-06 16:22:29.724: ERROR/Fatal Error(20515): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
02-06 16:22:29.724: ERROR/Fatal Error(20515): at org.apache.commons.vfs2.impl.StandardFileSystemManager.createInstance(StandardFileSystemManager.java:485)
02-06 16:22:29.724: ERROR/Fatal Error(20515): ... 23 more
安装过程中似乎出现了一些基本问题,但我不确定它是什么(Java不是我的第一语言;)。考虑到这是一个安卓项目,有什么特别的事情需要做吗?任何建议都将不胜感激。
我遇到了完全相同的问题。
我掌握了commons vfs源代码,并通过代码将错误跟踪到插件初始化中——基本上,我们的S3提供程序插件正在初始化,尽管不需要它。一些时髦的类加载器在S3 JAR中发现了vfs-providers.xml,并试图对其进行初始化,尽管URL不需要插件。
一旦我从WEB-INF/lib目录中删除了S3提供程序JAR,一切都很好。