0

下面是android尝试使用odata检索数据的代码。OdataWebNorthwindModelService 是代理类的名称(自动生成)...我按照http://weblogs.asp.net/uruit/archive/2011/09/13/accessing-odata-from-android-using-restlet.aspx寻求帮助...但我遇到了一些问题..请帮助我。

package com.example.odatajsondatagrabbing;


import northwindmodel.Category;

import org.restlet.ext.odata.Query;

import OdataWebNorthPackage.OdataWebNorthwindModelService;
import android.app.Activity;
import android.os.Bundle;


public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        OdataWebNorthwindModelService service = new OdataWebNorthwindModelService();

        Query<Category> query = service.createCategoryQuery("/Categories");

        for(Category cate: query){
            System.out.println("ID::"+cate.getCategoryId());
            System.out.println("Name::"+cate.getCategoryName());
            System.out.println("\n");
        }
    }
}

以下是我在运行应用程序时遇到的错误

    11-01 17:12:14.264: D/AndroidRuntime(689): Shutting down VM
11-01 17:12:14.264: W/dalvikvm(689): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-01 17:12:14.294: E/AndroidRuntime(689): FATAL EXCEPTION: main
11-01 17:12:14.294: E/AndroidRuntime(689): java.lang.NoClassDefFoundError: OdataWebNorthPackage.OdataWebNorthwindModelService
11-01 17:12:14.294: E/AndroidRuntime(689):  at com.example.odatajsondatagrabbing.MainActivity.onCreate(MainActivity.java:20)
11-01 17:12:14.294: E/AndroidRuntime(689):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-01 17:12:14.294: E/AndroidRuntime(689):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-01 17:12:14.294: E/AndroidRuntime(689):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-01 17:12:14.294: E/AndroidRuntime(689):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-01 17:12:14.294: E/AndroidRuntime(689):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-01 17:12:14.294: E/AndroidRuntime(689):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-01 17:12:14.294: E/AndroidRuntime(689):  at android.os.Looper.loop(Looper.java:123)
11-01 17:12:14.294: E/AndroidRuntime(689):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-01 17:12:14.294: E/AndroidRuntime(689):  at java.lang.reflect.Method.invokeNative(Native Method)
11-01 17:12:14.294: E/AndroidRuntime(689):  at java.lang.reflect.Method.invoke(Method.java:521)
11-01 17:12:14.294: E/AndroidRuntime(689):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-01 17:12:14.294: E/AndroidRuntime(689):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-01 17:12:14.294: E/AndroidRuntime(689):  at dalvik.system.NativeStart.main(Native Method)
11-01 17:17:14.385: I/Process(689): Sending signal. PID: 689 SIG: 9

当我尝试调试时,错误来自构造函数。下面是自动生成的代码

package OdataWebNorthPackage;

import northwindmodel.*;
import org.restlet.ext.odata.Query;
public class OdataWebNorthwindModelService extends org.restlet.ext.odata.Service {

    public OdataWebNorthwindModelService() {
        super("http://services.odata.org/Northwind/Northwind.svc");
    }

    public void addEntity(Category entity) throws Exception {
        addEntity("/Categories", entity);
    }

    public Query<Category> createCategoryQuery(String subpath) {
        return createQuery(subpath, Category.class);
    }

    public void addEntity(CustomerDemographic entity) throws Exception {
        addEntity("/CustomerDemographics", entity);
    }

    public Query<CustomerDemographic> createCustomerDemographicQuery(String subpath) {
        return createQuery(subpath, CustomerDemographic.class);
    }
}
4

1 回答 1

0

你完成了吗?

Project > Properties > Java Build Path > Order and Export > 最后,勾选您导入的 OData4j 库。

另外,不要在 UI 线程上使用 web 服务,考虑使用服务或AsyncTask

于 2012-11-23T12:09:42.730 回答