的Restlet无法获得与Android数据 [英] Restlet can't get the data with Android

查看:187
本文介绍了的Restlet无法获得与Android数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要得到的数据与此官方的OData 页中的Restlet: http://services.odata.org/OData/OData.svc/

I'm going to get data with Restlet of this official OData page: http://services.odata.org/OData/OData.svc/

我已经开始这个教程: <一href="http://weblogs.asp.net/uruit/archive/2011/09/13/accessing-odata-from-android-using-restlet.aspx" rel="nofollow">http://weblogs.asp.net/uruit/archive/2011/09/13/accessing-odata-from-android-using-restlet.aspx

我的问题是,到了最后,他的不能得到的元数据。但是,首先:

My problem is, that at the end, he can't get the metadata. But first:

当我试图生成的Restleg档案(5点),控制台将显示有关信息,凡与线条的日期

When I'm trying to generate the Restleg-Files (Point 5), the console is showing this, where the lines with are date are red:

---------------------------
OData client code generator
---------------------------
step 1 - check parameters
step 2 - check the ouput directory
step 3 - get the metadata descriptor
Nov 28, 2011 3:12:46 PM org.restlet.engine.http.connector.HttpClientHelper start
Information: Starting the default HTTP client
Nov 28, 2011 3:12:48 PM org.restlet.ext.odata.Service getMetadata
Information: Get the metadata for http://services.odata.org/OData/OData.svc/ at http://services.odata.org/OData/OData.svc/$metadata
Nov 28, 2011 3:12:48 PM org.restlet.engine.http.connector.HttpClientHelper start
Information: Starting the default HTTP client
step 4 - generate source code
Nov 28, 2011 3:12:48 PM org.restlet.engine.http.connector.HttpClientHelper start
Information: Starting the default HTTP client
Nov 28, 2011 3:12:49 PM org.restlet.ext.odata.Service getMetadata
Information: Get the metadata for http://services.odata.org/OData/OData.svc/ at http://services.odata.org/OData/OData.svc/$metadata
Nov 28, 2011 3:12:49 PM org.restlet.engine.http.connector.HttpClientHelper start
Information: Starting the default HTTP client
Nov 28, 2011 3:12:49 PM org.restlet.engine.http.connector.HttpClientHelper stop
Information: Stopping the default HTTP client
Nov 28, 2011 3:12:50 PM org.restlet.engine.http.connector.HttpClientHelper stop
Information: Stopping the default HTTP client
The source code has been generated in directory: C:\Projects\MyProjects\Android App\main\app\Java\Workspace\TestOData2\src

所以在文件生成,但在我前进的教程,复制类到我的Andr​​oid项目,导入库和编写以下code,然后我得到的错误下面。

So the files are generated, but when I'm going forward in the tutorial, copy the class into my Android project, import libraries and write the following code, then I get the error below.

public ArrayList<Product> getOdataSampleProduct(String zip) {           

    ODataDemoService proxy = new OdataDemoService();  

    try {       
        Query<Product> query = proxy.createProductQuery("Products(1)");
        Product product = query.iterator().next(); //breaks here
        Log.d("Test","id: "+product.getId()); //isn't logged

    }
    catch(Exception e) {
            //is catched before query.iterator().next()
    };

因此​​, LogCat中显示了这个错误(第3行是红色):

So, LogCat shows this error (line 3 is red):

...
11-29 09:01:01.039: INFO/org.restlet(700): Starting the default HTTP client
11-29 09:01:01.329: INFO/org.restlet(700): A recoverable error was detected (1001), attempting again in 2000 ms.
11-29 09:01:05.589: ERROR/org.restlet(700): Can't get the metadata for http://services.odata.org/OData/OData.svc/ (response's status: Communication Error (1001) - services.odata.org)
11-29 09:01:05.629: INFO/org.restlet(700): Get the metadata for http://services.odata.org/OData/OData.svc/ at http://services.odata.org/OData/OData.svc/$metadata
11-29 09:01:06.200: INFO/org.restlet(700): Starting the default HTTP client
11-29 09:01:06.329: INFO/org.restlet(700): A recoverable error was detected (1001), attempting again in 2000 ms.
11-29 09:01:06.359: DEBUG/dalvikvm(408): GC_EXPLICIT freed 3K, 5% free 6308K/6595K, paused 3ms+2ms
11-29 09:01:08.409: INFO/org.restlet(700): A recoverable error was detected (1001), attempting again in 2000 ms.
11-29 09:01:10.499: ERROR/org.restlet(700): Can't get the metadata for http://services.odata.org/OData/OData.svc/ (response's status: Communication Error (1001) - services.odata.org)
11-29 09:01:10.579: WARN/org.restlet(700): Can't parse the content of http://services.odata.org/OData/OData.svc/Products(1)
11-29 09:01:10.579: WARN/org.restlet(700): java.lang.Exception: Can't execute the query without the service's metadata.
11-29 09:01:10.579: WARN/org.restlet(700):     at org.restlet.ext.odata.Query.execute(Query.java:347)
11-29 09:01:10.579: WARN/org.restlet(700):     at org.restlet.ext.odata.Query.iterator(Query.java:642)
11-29 09:01:10.579: WARN/org.restlet(700):     at my.folder.testApp.MapView.getData(MapView.java:77)
11-29 09:01:10.579: WARN/org.restlet(700):     at my.folder.testApp.MapView.onCreate(MapView.java:141)
11-29 09:01:10.579: WARN/org.restlet(700):     at android.app.Activity.performCreate(Activity.java:4397)
11-29 09:01:10.579: WARN/org.restlet(700):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
11-29 09:01:10.579: WARN/org.restlet(700):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
11-29 09:01:10.579: WARN/org.restlet(700):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
11-29 09:01:10.579: WARN/org.restlet(700):     at android.app.ActivityThread.access$500(ActivityThread.java:122)
11-29 09:01:10.579: WARN/org.restlet(700):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
11-29 09:01:10.579: WARN/org.restlet(700):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-29 09:01:10.579: WARN/org.restlet(700):     at android.os.Looper.loop(Looper.java:132)
11-29 09:01:10.579: WARN/org.restlet(700):     at android.app.ActivityThread.main(ActivityThread.java:4123)
11-29 09:01:10.579: WARN/org.restlet(700):     at java.lang.reflect.Method.invokeNative(Native Method)
11-29 09:01:10.579: WARN/org.restlet(700):     at java.lang.reflect.Method.invoke(Method.java:491)
11-29 09:01:10.579: WARN/org.restlet(700):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
11-29 09:01:10.579: WARN/org.restlet(700):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
11-29 09:01:10.579: WARN/org.restlet(700):     at dalvik.system.NativeStart.main(Native Method)

这似乎有一个的问题与元数据,但我想不出什么。 你知道吗?

It seems that there is a problem with the metadata, but I can't figure out what. Any idea?

推荐答案

至少,我已经找到了一个解决方案: 我不得不把查询到的AsyncTask 。 之前,在UI线程,查询没有时间来得到答案。

At least, I've found a solution: I had to put the query into an AsyncTask. Before, in the UI thread, the query didn't have time to get an answer.

所以我把它改成了 doInBackground

这篇关于的Restlet无法获得与Android数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆