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帳戶的用戶名。我不知道有任何其他地方需要註冊我的端點模型類。任何幫助表示讚賞感謝
任何機會,你打錯了fory()的靜態導入?它應該是OfyService.ofy()而不是ObjectifyService.ofy()。 – stickfigure 2014-11-23 20:23:19
謝謝你,解決了這個問題....我把它作爲一個導入:導入com.googlecode.objectify.ObjectifyService而不是我自己的ofyservice類 – 2014-11-23 20:28:50
這是一個容易犯的錯誤,它可能是值得修改「最好的做法「推薦以其他方式進行註冊(比如說,一個servlet比賽監聽器)。另一方面,這也適用於測試用例。 – stickfigure 2014-11-25 09:52:06