我正在使用OData4j for Android,我无法获得实体

时间:2013-08-28 17:49:40

标签: java odata4j

这是我的代码:

package com.example.toggleDemo;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import org.odata4j.consumer.ODataConsumer;
import org.odata4j.core.OEntity;
import org.odata4j.jersey.consumer.ODataJerseyConsumer;
import java.util.List;
import java.util.ArrayList;

public class MainActivity  extends ListActivity {
    @Override
    public void  onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, GetExpenseReports()));
        getListView().setTextFilterEnabled(true);
    }

    ArrayList<String> GetExpenseReports()
    {
        ArrayList<String> listUI = new ArrayList<String>();
        ODataConsumer c = ODataJerseyConsumer.create("http://services.odata.org/Northwind/Northwind.svc/");
        List<OEntity> listCategories= (List<OEntity>) c.getEntities("Categories");
        for(OEntity category : listCategories) {
            listUI.add(String.format("%s-%s", category.getProperty("CategoryID").getValue().toString(), category.getProperty("CategoryName").getValue().toString()));
        }
        return  listUI;
    }
}

在模拟器中运行时,出现错误: 08-28 17:30:05.793:ERROR / AndroidRuntime(781):致命异常:主要         java.lang.NoClassDefFoundError:javax.ws.rs.ext.RuntimeDelegate         在org.odata4j.jersey.consumer.ODataJerseyConsumer。(ODataJerseyConsumer.java:22)         在org.odata4j.jersey.consumer.ODataJerseyConsumer。(ODataJerseyConsumer.java:14)         在org.odata4j.jersey.consumer.ODataJerseyConsumer $ Builder.build(ODataJerseyConsumer.java:93)         在org.odata4j.jersey.consumer.ODataJerseyConsumer.create(ODataJerseyConsumer.java:115)         在com.example.toggleDemo.MainActivity.GetExpenseReports(MainActivity.java:38)         在com.example.toggleDemo.MainActivity.onCreate(MainActivity.java:22)         在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)         在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)         在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)         在android.app.ActivityThread.access $ 2300(ActivityThread.java:125)         在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:2033)         在android.os.Handler.dispatchMessage(Handler.java:99)         在android.os.Looper.loop(Looper.java:123)         在android.app.ActivityThread.main(ActivityThread.java:4627)         at java.lang.reflect.Method.invokeNative(Native Method)         在java.lang.reflect.Method.invoke(Method.java:521)         在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)         在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)         在dalvik.system.NativeStart.main(本地方法)

提前致谢!

1 个答案:

答案 0 :(得分:0)

试试这个 它对我有用 ArrayList listUI = new ArrayList();         ODataConsumer c = ODataJerseyConsumer.create(&#34; http://services.odata.org/Northwind/Northwind.svc/&#34;);         OQueryRequest catagories = c.getEntities(&#34; Categories&#34;);

    Enumerable<OEntity> enumCatagory = catagories.execute();
    OEntity category = enumCatagory.first();
    System.out.println(enumCatagory.count());
    String str = String.format("%s-%s", category.getProperty("CategoryID").getValue().toString(), category.getProperty("CategoryName").getValue().toString());
    System.out.println(str);