[英]Java sardine webdav client on Android
I am currently implementing a WebDAV client for Android, which is based on sardine ( https://github.com/lookfirst/sardine ). 我目前正在为基于sardine( https://github.com/lookfirst/sardine )的Android实现WebDAV客户端。 The Android-Client is targeted for API level 15 (min-Api level).
Android客户端的目标是API级别15(最低Api级别)。
Right now I want to initialize the connection by using the Sardine Factory class like this: 现在,我想通过使用Sardine Factory类来初始化连接,如下所示:
sardine = SardineFactory.begin(user, password);
This piece of code is embedded within an Activity, that shall check if the credentials are valid. 这段代码嵌入了一个Activity中,该Activity将检查凭据是否有效。 By pressing on the OK button of the Activity a AsyncTask is started which embeds the codeline above
通过按“活动”的“确定”按钮,将启动AsyncTask,它将上面的代码行嵌入
AsyncTask<ServerCredentials, Void, ServerCredentials> verifyCredentialsTask = new AsyncTask<String[], Void, boolean>(){
@Override
protected boolean doInBackground(String[]...c) {
try {
String user = c[0];
String password = c[1]
sardine = SardineFactory.begin(user, password);
return true;
}
catch (Exception e) {
return false;
}
};
@Override
protected void onPostExecute(ServerCredentials sc) {
final Intent intent = new Intent();
...
setAccountAuthenticatorResult(intent.getExtras());
setResult(RESULT_OK);
finish();
}
};
When I debug the android application, I get up to the point where sardine is initialzed first from the SardineFactory. 当我调试android应用程序时,我到达了从SardineFactory首先初始化沙丁鱼的地步。 If I step over this line, an ExceptionInInitializerError is thrown.
如果我跳过这条线,则会引发ExceptionInInitializerError。 Although, there is a try catch statement, the whole activity crashes and the following exception trace can be seen in the logcat window:
尽管有一条try catch语句,但是整个活动崩溃,并且在logcat窗口中可以看到以下异常跟踪:
E/AndroidRuntime(10996): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(10996): java.lang.RuntimeException: An error occured while executing doInBackground()
E/AndroidRuntime(10996): at android.os.AsyncTask$3.done(AsyncTask.java:299)
E/AndroidRuntime(10996): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
E/AndroidRuntime(10996): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
E/AndroidRuntime(10996): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
E/AndroidRuntime(10996): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
E/AndroidRuntime(10996): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
E/AndroidRuntime(10996): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
E/AndroidRuntime(10996): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
E/AndroidRuntime(10996): at java.lang.Thread.run(Thread.java:856)
E/AndroidRuntime(10996): Caused by: java.lang.ExceptionInInitializerError
E/AndroidRuntime(10996): at com.github.sardine.SardineFactory.begin(SardineFactory.java:45)
E/AndroidRuntime(10996): at com.github.sardine.SardineFactory.begin(SardineFactory.java:34)
E/AndroidRuntime(10996): at com.github.sardine.SardineFactory.begin(SardineFactory.java:22)
I have already searched the web for an answer. 我已经在网上搜索了答案。 The definition of the ExceptionInInitializerError is to generic ( https://docs.oracle.com/javase/8/docs/api/index.html?java/lang/ExceptionInInitializerError.html ).
ExceptionInInitializerError的定义是通用的( https://docs.oracle.com/javase/8/docs/api/index.html?java/lang/ExceptionInInitializerError.html )。
If I attach the source to my referenced sardine.jar I can debug into the begin methods, and their overloads. 如果将源附加到引用的sardine.jar,则可以调试begin方法及其重载。 The final "begin" method, which is called is defined by
最终的“开始”方法被定义为
public static Sardine begin(String username, String password, ProxySelector proxy)
{
try {
return new SardineImpl(username, password, proxy);
} catch (Exception e) {
e.printStackTrace();
return null;
}
seems to cause the problem. 似乎是造成问题的原因。
As you can see I already modified it with a try catch, to see if I can catch the exception that is thrown. 如您所见,我已经使用try catch对其进行了修改,以查看是否可以捕获所引发的异常。 But as soon as I step over the SardineImpl construtor, the ExceptionInInitializerError is thrown.
但是,一旦我越过SardineImpl构造函数,就会引发ExceptionInInitializerError。 I have no chance to catch it.
我没有机会抓住它。
I assume, that some library is still missing. 我认为某些图书馆仍然缺失。 I'm building the sardine.jar within eclipse by a maven build script (clean install).
我正在通过Maven构建脚本(全新安装)在Eclipse中构建sardine.jar。 The source is unchanged except I added the following missing libraries
除了我添加了以下缺少的库以外,源没有变化
ant-1.9.2.jar
commons-codec-1.6.jar
commons-logging-1.1.3.jar
httpclient-4.5.jar
httpcore-4.3.2.jar
slf4j-api-1.7.12.jar
slf4j-jdk14-1.7.12.jar
The hooks in the Eclipse project settings (Java Build Path -> Order and Export) are set for all external libraries. Eclipse项目设置(Java Build Path-> Order and Export)中的挂钩是为所有外部库设置的。 Therefore I assume nothing is missing, when the APK is build and installed on the target device.
因此,当在目标设备上构建并安装APK时,我认为没有任何丢失。
Does anyone has experienced a similar problem? 有没有人遇到过类似的问题? How can I interpret the ExceptionInInitializerError exception?
如何解释ExceptionInInitializerError异常?
just to close this issue. 只是为了解决这个问题。 Due to the fact, that I wanted to access an ownCloud instance via webdav i decided to drop the sardine library and go for the native ownCloud library ( https://github.com/owncloud/android-library ).
由于这个事实,我想通过webdav访问ownCloud实例,所以我决定删除沙丁鱼库,然后转到本机的ownCloud库( https://github.com/owncloud/android-library )。 This library included a pretty good sample client and worked perfect for my project.
该库包括一个很好的示例客户端,并且非常适合我的项目。
Thanks 谢谢
I was able to overcome the issue by using the Sardine Library, which was rewritten for Android as an Android-Library project ( https://github.com/aflx/Sardine-Android ). 通过使用Sardine库,我能够解决该问题,该库已作为Android-Library项目( https://github.com/aflx/Sardine-Android )被Android重写。 I imported the project into my Eclipse Workspace, built it and linked the jar file from the bin subdirectory into my project.
我将项目导入到Eclipse Workspace中,进行了构建,并将jar文件从bin子目录链接到了我的项目中。 Finally I had to set the hook in the project's settings "Build Path" -> "Order and Export".
最后,我必须在项目的设置“ Build Path”->“ Order and Export”中设置钩子。
This solution solved the issue above. 此解决方案解决了上述问题。 Now, I am one step further, but still get an exception.
现在,我又走了一步,但仍然有例外。 When I try to list the files and folder on the remote server with the following code line
当我尝试使用以下代码行列出远程服务器上的文件和文件夹时
List<DavResource> res = sardine.list(hostName);
I get an NoClassDefFoundError which tells me that he couldn't find the class org.simpleframework.xml.core.Persister. 我收到一个NoClassDefFoundError,它告诉我他找不到类org.simpleframework.xml.core.Persister。
E/AndroidRuntime(26434): Caused by: java.lang.NoClassDefFoundError: org.simpleframework.xml.core.Persister
Within the project settings of the Sardine-Android I have linked the 在Sardine-Android的项目设置中,我已将
simple-xml-2.6.2.jar
which should contain the missing class. 其中应包含缺少的类。 Furthermore I have read in other sites ( http://android.phonesdevelopers.com/1011_19444554/ ), that it might be necessary to exclude classes from the build path, because they might conflict with build in classes.
此外,我在其他站点( http://android.phonesdevelopers.com/1011_19444554/ )中已读到,可能有必要从构建路径中排除类,因为它们可能与构建类冲突。 Unfortunately, they are working with gradle, which I haven't worked with yet.
不幸的是,他们正在使用gradle,而我还没有使用过。 I will search the web for a solution, but maybe someone knows hot to do this?
我将在网上搜索解决方案,但也许有人知道这样做很热吗?
i have similar problems trying to make Sardine work on Android. 我在尝试使Sardine在Android上工作时遇到类似的问题。 I am using Android Studio, building with SDK 21. I simply downloaded the Sardine-Android sources and added them to the project in the folder
/app/src/main/java
and simple-xml-2.6.3.jar
in the /app/libs
. 我使用过Android Studio,与SDK 21建立我只是下载了沙丁鱼,Android的代码,将其添加到该文件夹的项目
/app/src/main/java
和simple-xml-2.6.3.jar
在/app/libs
。 I am using ActionBarActivity
. 我正在使用
ActionBarActivity
。 The code builds without errors. 该代码生成没有错误。 I however get another error in the same line, but not
NoClassDefFoundError
但是我在同一行中遇到另一个错误,但是没有
NoClassDefFoundError
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.