我正在尝试在Alfresco上的文件夹中上传文件,但是我得到了这个例外,我试图在过去两天没有任何机会解决这个问题。
我使用的是Alfresco Mobile SDK for Android和alfresco Community 4.2。
这是我如何尝试上传文件,告诉我我是否做错了什么:
File fileToUpload = new File(selectedFilePath);
if((fileToUpload != null) && fileToUpload.isFile()) {
Log.d(MainActivity.DEBUGING, "File to upload's name: " + fileToUpload.getName());
String fileName = fileToUpload.getName();
String mimeType = getMimeType(selectedFilePath);
ContentFile contentFile = new ContentFileImpl(fileToUpload, fileName, mimeType);
try {
Log.w(MainActivity.DEBUGING, "create file: " + fileName + " of type: " + mimeType + " in: " + selectedFilePath);
session.getServiceRegistry().getDocumentFolderService().createDocument(currentFolder, fileName, properties, contentFile);
Toast.makeText(this, "file: " + fileName + " of type: " + mimeType + "in: " + selectedFilePath + " was created", Toast.LENGTH_LONG).show();
}
catch(org.alfresco.mobile.android.api.exceptions.AlfrescoServiceException e) {
Toast.makeText(this, "Upload failed ! ", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
//
这是我在日志中的例外:
04-22 11:29:09.475: W/System.err(616): org.alfresco.mobile.android.api.exceptions.AlfrescoServiceException: org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException: Cannot access http://192.168.1.15:8080/alfresco/api/-default-/public/cmis/versions/1.0/atom/children?id=37f6caba-bd45-4191-96b3-3604d4cbb9be&versioningState=major: null
04-22 11:29:09.475: W/System.err(616): at org.alfresco.mobile.android.api.exceptions.impl.ExceptionHelper.convertException(ExceptionHelper.java:119)
04-22 11:29:09.475: W/System.err(616): at org.alfresco.mobile.android.api.services.impl.AlfrescoService.convertException(AlfrescoService.java:302)
04-22 11:29:09.475: W/System.err(616): at org.alfresco.mobile.android.api.services.impl.AbstractDocumentFolderServiceImpl.createDocument(AbstractDocumentFolderServiceImpl.java:542)
04-22 11:29:09.475: W/System.err(616): at org.alfresco.mobile.android.api.services.impl.AbstractDocumentFolderServiceImpl.createDocument(AbstractDocumentFolderServiceImpl.java:458)
04-22 11:29:09.484: W/System.err(616): at org.valueit.turboecm.MyTurboECMBrowserActivity.onActivityResult(MyTurboECMBrowserActivity.java:364)
04-22 11:29:09.484: W/System.err(616): at android.app.Activity.dispatchActivityResult(Activity.java:5192)
04-22 11:29:09.484: W/System.err(616): at android.app.ActivityThread.deliverResults(ActivityThread.java:3137)
04-22 11:29:09.484: W/System.err(616): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3184)
04-22 11:29:09.484: W/System.err(616): at android.app.ActivityThread.access$1100(ActivityThread.java:130)
04-22 11:29:09.494: W/System.err(616): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
04-22 11:29:09.494: W/System.err(616): at android.os.Handler.dispatchMessage(Handler.java:99)
04-22 11:29:09.494: W/System.err(616): at android.os.Looper.loop(Looper.java:137)
04-22 11:29:09.494: W/System.err(616): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-22 11:29:09.504: W/System.err(616): at java.lang.reflect.Method.invokeNative(Native Method)
04-22 11:29:09.504: W/System.err(616): at java.lang.reflect.Method.invoke(Method.java:511)
04-22 11:29:09.504: W/System.err(616): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-22 11:29:09.504: W/System.err(616): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-22 11:29:09.514: W/System.err(616): at dalvik.system.NativeStart.main(Native Method)
04-22 11:29:09.514: W/System.err(616): Caused by: org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException: Cannot access http://192.168.1.15:8080/alfresco/api/-default-/public/cmis/versions/1.0/atom/children?id=37f6caba-bd45-4191-96b3-3604d4cbb9be&versioningState=major: null
04-22 11:29:09.514: W/System.err(616): at org.alfresco.mobile.android.api.network.NetworkHttpInvoker.invoke(NetworkHttpInvoker.java:291)
04-22 11:29:09.514: W/System.err(616): at org.alfresco.mobile.android.api.network.NetworkHttpInvoker.invokePOST(NetworkHttpInvoker.java:74)
04-22 11:29:09.524: W/System.err(616): at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.post(AbstractAtomPubService.java:616)
04-22 11:29:09.524: W/System.err(616): at org.apache.chemistry.opencmis.client.bindings.spi.atompub.ObjectServiceImpl.createDocument(ObjectServiceImpl.java:116)
04-22 11:29:09.524: W/System.err(616): at org.alfresco.mobile.android.api.services.impl.AbstractDocumentFolderServiceImpl.createDocument(AbstractDocumentFolderServiceImpl.java:511)
04-22 11:29:09.524: W/System.err(616): ... 15 more
04-22 11:29:09.534: W/System.err(616): Caused by: android.os.NetworkOnMainThreadException
04-22 11:29:09.544: W/System.err(616): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
04-22 11:29:09.544: W/System.err(616): at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
04-22 11:29:09.544: W/System.err(616): at libcore.io.IoBridge.connectErrno(IoBridge.java:144)
04-22 11:29:09.544: W/System.err(616): at libcore.io.IoBridge.connect(IoBridge.java:112)
04-22 11:29:09.554: W/System.err(616): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
04-22 11:29:09.554: W/System.err(616): at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
04-22 11:29:09.554: W/System.err(616): at java.net.Socket.connect(Socket.java:842)
04-22 11:29:09.564: W/System.err(616): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:76)
04-22 11:29:09.564: W/System.err(616): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
04-22 11:29:09.564: W/System.err(616): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:341)
04-22 11:29:09.564: W/System.err(616): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
04-22 11:29:09.564: W/System.err(616): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
04-22 11:29:09.574: W/System.err(616): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
04-22 11:29:09.574: W/System.err(616): at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
04-22 11:29:09.574: W/System.err(616): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
04-22 11:29:09.584: W/System.err(616): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
04-22 11:29:09.584: W/System.err(616): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273)
04-22 11:29:09.584: W/System.err(616): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
04-22 11:29:09.584: W/System.err(616): at org.alfresco.mobile.android.api.network.NetworkHttpInvoker.invoke(NetworkHttpInvoker.java:264)
04-22 11:29:09.584: W/System.err(616): ... 19 more
04-22 11:29:09.596: W/debogage(616): ====================> filePath: /dev/10173306_804433689584264_1962438159_n.jpg
//我也试过这个在后台创建文件,但这次我在appInclackgroud启动时在我的应用程序中出现黑屏,并且一段时间后应用停止响应:(
DocumentCreateLoader contentCreator = new DocumentCreateLoader(this, session, currentFolder, fileName, properties, contentFile);
contentCreator.loadInBackground();
答案 0 :(得分:1)
Aloah,
为其他开发者提供快速提示:
如果在崩溃后在日志中看到此行
04-22 11:29:09.534:W / System.err(616):引起: android.os.NetworkOnMainThreadException
这意味着您需要在后台线程中运行代码,如AsyncTask,Loader,Thread ...而不是应用程序的Main / UI Thread。 任何与网络相关的操作都必须在Android主线程外部完成。