我对 Android 上的沙丁鱼有一个大问题。我已经下载了适用于 Android 的 Sardine 库并在我的项目中使用它。PUT 和 GET 方法有效,但 LIST 方法无效,我不知道为什么。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
Sardine sardine = SardineFactory.begin("username", "password");
List<DavResource> resources = sardine.list("https://myserver.com/");
for (DavResource res : resources)
{
Log.i("Resources", res.getName());
}
} catch (ExceptionInInitializerError e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
}
}
这是我的程序的 LogCat 控制台:
02-23 13:39:50.741: I/Sardine(1797): init
02-23 13:39:50.741: I/Sardine(1797): list
02-23 13:39:51.691: D/dalvikvm(1797): GC_CONCURRENT freed 244K, 13% free 2474K/2844K, paused 14ms+20ms, total 53ms
02-23 13:39:51.902: I/dalvikvm(1797): Could not find method javax.xml.stream.XMLInputFactory.newInstance, referenced from method org.simpleframework.xml.stream.StreamProvider.<init>
02-23 13:39:51.902: W/dalvikvm(1797): VFY: unable to resolve static method 4066: Ljavax/xml/stream/XMLInputFactory;.newInstance ()Ljavax/xml/stream/XMLInputFactory;
02-23 13:39:51.902: D/dalvikvm(1797): VFY: replacing opcode 0x71 at 0x0003
02-23 13:39:51.914: W/dalvikvm(1797): VFY: unable to find class referenced in signature (Ljavax/xml/stream/XMLEventReader;)
02-23 13:39:51.922: W/dalvikvm(1797): VFY: unable to find class referenced in signature (Ljavax/xml/stream/XMLEventReader;)
02-23 13:39:51.934: I/dalvikvm(1797): Could not find method javax.xml.stream.XMLInputFactory.createXMLEventReader, referenced from method org.simpleframework.xml.stream.StreamProvider.provide
02-23 13:39:51.934: W/dalvikvm(1797): VFY: unable to resolve virtual method 4064: Ljavax/xml/stream/XMLInputFactory;.createXMLEventReader (Ljava/io/InputStream;)Ljavax/xml/stream/XMLEventReader;
02-23 13:39:51.934: D/dalvikvm(1797): VFY: replacing opcode 0x6e at 0x0002
02-23 13:39:51.934: I/dalvikvm(1797): Could not find method javax.xml.stream.XMLInputFactory.createXMLEventReader, referenced from method org.simpleframework.xml.stream.StreamProvider.provide
02-23 13:39:51.934: W/dalvikvm(1797): VFY: unable to resolve virtual method 4065: Ljavax/xml/stream/XMLInputFactory;.createXMLEventReader (Ljava/io/Reader;)Ljavax/xml/stream/XMLEventReader;
02-23 13:39:51.934: D/dalvikvm(1797): VFY: replacing opcode 0x6e at 0x0002
02-23 13:39:52.122: D/dalvikvm(1797): GC_CONCURRENT freed 313K, 15% free 2607K/3044K, paused 20ms+8ms, total 69ms
02-23 13:39:52.122: W/System.err(1797): org.simpleframework.xml.core.PersistenceException: Element 'propstat' is already used with @org.simpleframework.xml.Element(data=false, name=, required=true, type=void) on field 'propstat' protected de.aflx.sardine.model.Propstat de.aflx.sardine.model.Response.propstat at line 1
02-23 13:39:52.132: W/System.err(1797): at org.simpleframework.xml.core.Variable$Adapter.read(Variable.java:484)
02-23 13:39:52.132: W/System.err(1797): at org.simpleframework.xml.core.Variable$Adapter.read(Variable.java:462)
02-23 13:39:52.132: W/System.err(1797): at org.simpleframework.xml.core.Composite.readVariable(Composite.java:623)
02-23 13:39:52.132: W/System.err(1797): at org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
02-23 13:39:52.132: W/System.err(1797): at org.simpleframework.xml.core.Composite.readUnion(Composite.java:549)
02-23 13:39:52.132: W/System.err(1797): at org.simpleframework.xml.core.Composite.readElement(Composite.java:532)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite.readElements(Composite.java:445)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite.read(Composite.java:201)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite.read(Composite.java:148)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.CompositeInlineList.read(CompositeInlineList.java:190)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.CompositeInlineList.read(CompositeInlineList.java:167)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.CompositeInlineList.read(CompositeInlineList.java:124)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite.readVariable(Composite.java:623)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite.readInstance(Composite.java:573)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite.readUnion(Composite.java:549)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite.readElement(Composite.java:532)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite.readElements(Composite.java:445)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite.access$400(Composite.java:59)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite.read(Composite.java:201)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Composite.read(Composite.java:148)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Traverser.read(Traverser.java:92)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Persister.read(Persister.java:625)
02-23 13:39:52.142: W/System.err(1797): at org.simpleframework.xml.core.Persister.read(Persister.java:606)
02-23 13:39:52.152: W/System.err(1797): at org.simpleframework.xml.core.Persister.read(Persister.java:584)
02-23 13:39:52.152: W/System.err(1797): at org.simpleframework.xml.core.Persister.read(Persister.java:543)
02-23 13:39:52.152: W/System.err(1797): at de.aflx.sardine.impl.handler.MultiStatusResponseHandler.getMultistatus(MultiStatusResponseHandler.java:69)
02-23 13:39:52.152: W/System.err(1797): at de.aflx.sardine.impl.handler.MultiStatusResponseHandler.handleResponse(MultiStatusResponseHandler.java:51)
02-23 13:39:52.152: W/System.err(1797): at de.aflx.sardine.impl.handler.MultiStatusResponseHandler.handleResponse(MultiStatusResponseHandler.java:1)
02-23 13:39:52.152: W/System.err(1797): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:657)
02-23 13:39:52.152: W/System.err(1797): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:627)
02-23 13:39:52.152: W/System.err(1797): at de.aflx.sardine.impl.SardineImpl.execute(SardineImpl.java:772)
02-23 13:39:52.152: W/System.err(1797): at de.aflx.sardine.impl.SardineImpl.list(SardineImpl.java:401)
02-23 13:39:52.152: W/System.err(1797): at de.aflx.sardine.impl.SardineImpl.list(SardineImpl.java:385)
02-23 13:39:52.152: W/System.err(1797): at com.example.webdav.MainActivity.onCreate(MainActivity.java:32)
02-23 13:39:52.162: W/System.err(1797): at android.app.Activity.performCreate(Activity.java:5104)
02-23 13:39:52.162: W/System.err(1797): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-23 13:39:52.162: W/System.err(1797): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-23 13:39:52.162: W/System.err(1797): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-23 13:39:52.162: W/System.err(1797): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-23 13:39:52.162: W/System.err(1797): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-23 13:39:52.162: W/System.err(1797): at android.os.Handler.dispatchMessage(Handler.java:99)
02-23 13:39:52.162: W/System.err(1797): at android.os.Looper.loop(Looper.java:137)
02-23 13:39:52.162: W/System.err(1797): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-23 13:39:52.162: W/System.err(1797): at java.lang.reflect.Method.invokeNative(Native Method)
02-23 13:39:52.162: W/System.err(1797): at java.lang.reflect.Method.invoke(Method.java:511)
02-23 13:39:52.162: W/System.err(1797): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-23 13:39:52.162: W/System.err(1797): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-23 13:39:52.162: W/System.err(1797): at dalvik.system.NativeStart.main(Native Method)
02-23 13:39:52.162: W/System.err(1797): java.lang.NullPointerException
02-23 13:39:52.174: W/System.err(1797): at de.aflx.sardine.impl.SardineImpl.list(SardineImpl.java:403)
02-23 13:39:52.174: W/System.err(1797): at de.aflx.sardine.impl.SardineImpl.list(SardineImpl.java:385)
02-23 13:39:52.174: W/System.err(1797): at com.example.webdav.MainActivity.onCreate(MainActivity.java:32)
02-23 13:39:52.174: W/System.err(1797): at android.app.Activity.performCreate(Activity.java:5104)
02-23 13:39:52.174: W/System.err(1797): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-23 13:39:52.174: W/System.err(1797): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
02-23 13:39:52.174: W/System.err(1797): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-23 13:39:52.174: W/System.err(1797): at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-23 13:39:52.174: W/System.err(1797): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-23 13:39:52.174: W/System.err(1797): at android.os.Handler.dispatchMessage(Handler.java:99)
02-23 13:39:52.182: W/System.err(1797): at android.os.Looper.loop(Looper.java:137)
02-23 13:39:52.182: W/System.err(1797): at android.app.ActivityThread.main(ActivityThread.java:5039)
02-23 13:39:52.182: W/System.err(1797): at java.lang.reflect.Method.invokeNative(Native Method)
02-23 13:39:52.182: W/System.err(1797): at java.lang.reflect.Method.invoke(Method.java:511)
02-23 13:39:52.182: W/System.err(1797): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-23 13:39:52.182: W/System.err(1797): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-23 13:39:52.182: W/System.err(1797): at dalvik.system.NativeStart.main(Native Method)
需要的帮助。
非常感谢!