簡體   English   中英

無法在Google App Engine端點中使用插入方法

[英]Unable to use the insert method in google app engine endpoints

我正在構建一個訪問服務器的android應用。 我正在使用完整的Google解決方案。 后端在GAE中,我使用端點公開我的API,我也在使用GCM。 我使用android studio提供的自動生成工具來獲取我的課程。

在我的應用程序模塊中,我有一個名為offer的類,在這里我將數據發送到服務器,還有AsyncTask類,該類允許進行api調用。

在我的后端模塊中,我有公開的API,也有一個類商品,由android studio和應用程序引擎sdk從中生成API。

現在我的問題是我嘗試了一次,但是導致失敗,就像app和后端中的類不兼容一樣。 盡管它們是相同的,但實際上后端中的一個是應用程序中一個的簡單副本,不同之處在於我添加的“ objectify”注釋。 以下是我的代碼片段和項目結構的屏幕截圖。

    public class InsertOfferAsyncTask extends AsyncTask <Offer, Void, Boolean>{

    private static OfferApi offer_service;
    private Context context;

    public InsertOfferAsyncTask(Context context) {
     this.context = context;
    }

    protected Boolean doInBackground(Offer... offer) {

      if (offer_service == null) {

        OfferApi.Builder builder = new OfferApi.Builder(AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), null)
                .setRootUrl("https://flawless-snow-95011.appspot.com/_ah/api/");


        offer_service = builder.build();
    }


    try {
        offer_service.insert(offer[0]); //this where I make the actual API call, I know I shouldn't use Object, it was an attempt to make it work
    } catch (IOException e) {
        e.printStackTrace();
    }


    return true;
    }

這是我稱為AsyncTask的一部分,即上面的代碼。

     Log.i("offer", offer.getUsr_id());
            Log.i("offer_id", String.valueOf(offer.getId()));
            Log.i("offer_date", offer.getPost());
            new         InsertOfferAsyncTask(getActivity().getBaseContext()).execute(offer);
            getActivity().finish();

上面的所有代碼均來自我的應用程序模塊,以下是該代碼生成的終結點代碼,我僅發布我調用的部分。

    @ApiMethod(
        name = "insert",
        path = "offer",
        httpMethod = ApiMethod.HttpMethod.POST)
public Offer insert(Offer offer) {

    ofy().save().entity(offer).now();
    logger.info("Created Offer with ID: " + offer.getId());

    return ofy().load().entity(offer).now();
}

我的項目樹的屏幕截圖

我現在需要的是如何使用將數據發送到服務器的方法。 我知道我可以連接到服務器,經過測試。

這是我嘗試構建時收到的錯誤消息。

    Error:(233, 73) error: no suitable method found for execute(.model.Offer) 
    method AsyncTask.execute(Runnable) is not applicable
    (actual argument .model.Offer cannot be converted to Runnable by method invocation conversion)
    method AsyncTask.execute(backend.model.offerApi.model.Offer...) is not applicable
    (argument type app.model.Offer does not conform to vararg element type backend.model.offerApi.model.Offer)

有幫助嗎? 我應該使用JSON嗎(我懷疑,工作是由自動生成的類完成的,如構建器中所示)

可能是您正在使用兩個不同的“ Offer”對象app.model.Offerbackend.model.offerApi.model.Offer嗎?

backend.model.offerApi.model.Offer類型似乎是為您的Endpoints API生成的類型,您需要在客戶端(android)端的任何地方使用該類型。

我相信您應該創建一個單獨的項目,其中包含android應用程序和api之間共享的所有類。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM