我正在尝试创建一个可在云上连接的android应用程序。我大胆地尝试使用theyr api连接到koofr.eu。

Koofr是一种安全,简单的方法来存储,备份和共享您的照片,视频和文档。通过任何设备,无论何时何地,无论是计算机,电话还是平板电脑,都可以访问您的所有数据。安全与保障是我们软件和思维方式的核心。

他们提供的有关Java的文档很小,看起来很简单,但是库却很大。另外,我遇​​到的问题之一是该库使用了另外3-4个库来工作。

这是我的应用程序gradle的样子:

dependencies {
   /*compile fileTree(dir: 'libs', include: ['*.jar']) */
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'net.koofr:java-koofr:1.2.8'
    compile ("org.restlet.jse:org.restlet.ext.httpclient:2.1.2") {
        exclude group: 'org.restlet', module: 'jse'
        exclude group: 'org.restlet.ext', module: 'ss1'
    }
    compile 'org.apache.httpcomponents:httpclient:4.3.5'
    compile 'org.restlet.jse:org.restlet.ext.jackson:2.1.2'


    android {
        packagingOptions {
            exclude 'META-INF/DEPENDENCIES.txt'
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/NOTICE.txt'
            exclude 'META-INF/NOTICE'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/DEPENDENCIES'
            exclude 'META-INF/notice.txt'
            exclude 'META-INF/license.txt'
            exclude 'META-INF/dependencies.txt'
            exclude 'META-INF/ASL2.0'
            exclude 'META-INF/services/org.restlet.engine.ClientHelper'
        }
    }


在清单中,我添加了用户权限以允许应用程序中的Internet:

<uses-permission android:name="android.permission.INTERNET" />


我的主要活动代码很简单。

    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                StorageApi api = DefaultClientFactory.create("app.koofr.eu", "*********", "******");
                Log.i("TEST","User Info: "+api.getUserInfo());
            } catch (StorageApiException e) {
                e.printStackTrace();
                Log.i("TEST","Mesaj: "+e.getMessage());
            }
        }
    });


基本上,异常消息如下:

Internal Connector Error (1002) - The connector encountered an unexpected condition which prevented it from fulfilling the request


但这并没有以任何方式帮助我找到问题的解决方案,因此我发现了一些试图理解的警告。

03-12 21:50:44.617    7027-7027/com.example.marian.digimusicstream W/System.err﹕ Starting the Apache HTTP client
03-12 21:50:44.619    7027-7027/com.example.marian.digimusicstream W/System.err﹕ Error while handling an HTTP client call
03-12 21:50:44.619    7027-7027/com.example.marian.digimusicstream W/System.err﹕ [ 03-12 21:50:44.619  7027: 7027 W/System.err ]
    android.os.NetworkOnMainThreadException
03-12 21:50:44.619    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147)
03-12 21:50:44.619    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at java.net.InetAddress.lookupHostByName(InetAddress.java:423)
03-12 21:50:44.619    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at java.net.InetAddress.getLocalHost(InetAddress.java:396)
03-12 21:50:44.619    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.engine.adapter.ClientCall.getLocalAddress(ClientCall.java:67)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.engine.adapter.ClientCall.<init>(ClientCall.java:90)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.ext.httpclient.internal.HttpMethodCall.<init>(HttpMethodCall.java:107)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.ext.httpclient.HttpClientHelper.create(HttpClientHelper.java:298)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.engine.adapter.ClientAdapter.toSpecific(ClientAdapter.java:159)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.engine.adapter.HttpClientHelper.handle(HttpClientHelper.java:111)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.Client.handle(Client.java:180)
03-12 21:50:44.620    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.resource.ClientResource.handle(ClientResource.java:1136)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.resource.ClientResource.handleOutbound(ClientResource.java:1225)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.resource.ClientResource.handle(ClientResource.java:1068)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.resource.ClientResource.handle(ClientResource.java:1044)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.resource.ClientResource.handle(ClientResource.java:950)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at org.restlet.resource.ClientResource.get(ClientResource.java:658)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at net.koofr.api.v2.StorageApi.authenticate(StorageApi.java:150)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at net.koofr.api.v2.DefaultClientFactory.create(DefaultClientFactory.java:66)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at com.example.marian.digimusicstream.LoginActivity$1.onClick(LoginActivity.java:51)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.view.View.performClick(View.java:4763)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.view.View$PerformClick.run(View.java:19821)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5274)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
03-12 21:50:44.621    7027-7027/com.example.marian.digimusicstream W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
03-12 21:50:44.622    7027-7027/com.example.marian.digimusicstream W/System.err﹕ A recoverable error was detected (1002), attempting again in 2000 ms.


如果有人有任何小的想法,我将不胜感激。谢谢。

最佳答案

android.os.NetworkOnMainThreadException


不要在UI线程上进行网络调用!
将可能会费时的所有内容放入新线程中,以免冻结UI。
有关更多信息,请参见此question

10-04 14:32