0

我正在使用谷歌雲端點與對象來存儲應用程序的數據。如果我的API請求來創建IVE我得到:沒有課程註冊的雲端點

com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request 
11-23 09:39:03.711 27884-28100/com.nicky W/System.err﹕ { 
11-23 09:39:03.711 27884-28100/com.nicky W/System.err﹕ "code": 400, 
11-23 09:39:03.711 27884-28100/com.nicky W/System.err﹕ "errors": [ 
11-23 09:39:03.711 27884-28100/com.nicky W/System.err﹕ { 
11-23 09:39:03.711 27884-28100/com.nicky W/System.err﹕ "domain": "global", 
11-23 09:39:03.711 27884-28100/com.nicky W/System.err﹕ "message": "java.lang.IllegalArgumentException: No class 'com.nicky.mybackend.Post' was registered", 
11-23 09:39:03.711 27884-28100/com.nicky W/System.err﹕ "reason": "badRequest" 
11-23 09:39:03.711 27884-28100/com.nicky W/System.err﹕ } 
11-23 09:39:03.711 27884-28100/com.nicky W/System.err﹕ ], 
11-23 09:39:03.711 27884-28100/com.nicky W/System.err﹕ "message": "java.lang.IllegalArgumentException: No class 'com.nicky.mybackend.Post' was registered" 
11-23 09:39:03.711 27884-28100/com.nicky W/System.err﹕ } 

我知道我有Post.class在ObjectifyService類註冊,和我能夠在Android客戶端創建後的對象。這裏是objectifyService類:

public class OfyService { 

    static { 
     ObjectifyService.register(RegistrationRecord.class); 
     ObjectifyService.register(Post.class); 
    } 

    public static Objectify ofy() { 
     return ObjectifyService.ofy(); 
    } 

    public static ObjectifyFactory factory() { 
     return ObjectifyService.factory(); 
    } 
} 

這裏是終點法從我的Android客戶端我打電話:

@ApiMethod(
      name = "insert", 
      path = "post", 
      httpMethod = ApiMethod.HttpMethod.POST) 
    public Post insert(Post post) { 
     ofy().save().entity(post).now(); 
     logger.info("Created Post with ID: " + post.getId()); 

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

我打電話的後端從的AsyncTask像這樣:

我還沒有確保服務器端的東西,但我使用GoogleAccountCredential提出的請求,該用戶名中包含電話上的Android帳戶的用戶名。我不知道有任何其他地方需要註冊我的端點模型類。任何幫助表示讚賞感謝

+5

任何機會,你打錯了fory()的靜態導入?它應該是OfyService.ofy()而不是ObjectifyService.ofy()。 – stickfigure 2014-11-23 20:23:19

+1

謝謝你,解決了這個問題....我把它作爲一個導入:導入com.googlecode.objectify.ObjectifyService而不是我自己的ofyservice類 – 2014-11-23 20:28:50

+0

這是一個容易犯的錯誤,它可能是值得修改「最好的做法「推薦以其他方式進行註冊(比如說,一個servlet比賽監聽器)。另一方面,這也適用於測試用例。 – stickfigure 2014-11-25 09:52:06

回答

2

我不希望分配,賦予了正確的答案,但這個意見有正確的答案:

塊引用您有OFY錯誤的靜態導入任何機會()?它應該是OfyService.ofy(),而不是ObjectifyService.ofy()

所以,當你創建端點Android Studio中自動導入庫

import com.googlecode.objectify.ObjectifyService; 

當你需要導入OFY類。

所以,在我的情況我已經導入它,而不是其他的,甚至我把我OFY類的名稱,如:

OfyService.ofy().save().entity 

OfyService.ofy().delete().entity