在GAE中嘗試使用端點檢索列表時,似乎出現錯誤。該錯誤是如下:「Id不能爲零」 - GoogleJsonResponseException 400錯誤請求
04-08 01:01:30.145: I/System.out(14650): com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
04-08 01:01:30.145: I/System.out(14650): {
04-08 01:01:30.145: I/System.out(14650): "code": 400,
04-08 01:01:30.145: I/System.out(14650): "errors": [
04-08 01:01:30.145: I/System.out(14650): {
04-08 01:01:30.145: I/System.out(14650): "domain": "global",
04-08 01:01:30.145: I/System.out(14650): "message": "java.lang.IllegalArgumentException: id cannot be zero",
04-08 01:01:30.145: I/System.out(14650): "reason": "badRequest"
04-08 01:01:30.145: I/System.out(14650): }
04-08 01:01:30.145: I/System.out(14650): ],
04-08 01:01:30.145: I/System.out(14650): "message": "java.lang.IllegalArgumentException: id cannot be zero"
04-08 01:01:30.145: I/System.out(14650): }
這是我想在我的端點使用方法:
@SuppressWarnings({ "cast", "unchecked"})
public List<Comercio> listComercio() {
EntityManager mgr = getEntityManager();
List<Comercio> result= new ArrayList<Comercio>();
try {
Query query = mgr.createQuery("select c from Comercio c", Comercio.class);
for (Object obj : (List<Object>) query.getResultList()) {
result.add((Comercio) obj);
}
} finally {
mgr.close();
}
return result;
}
}
這是實體類:
@Entity
public class Comercio{
@Id
private Long id;
private String title;
private String url;
private String NEWSTYPE;
public Comercio() {
}
public Long getId() {
return id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public void setNewstypeid(String newstypeid) {
this.NEWSTYPE = newstypeid;
}
public String getNewstypeid() {
return NEWSTYPE;
}
}
這是從的AsyncTask我的Android項目:
public class AsyncDatastoreArticles extends CloudAsyncTask {
AsyncDatastoreArticles(Home activity) {
super(activity);
}
@Override
protected void doInBackground() throws IOException {
// TODO Auto-generated method stub
List<Comercio> list = endpoint.listComercio().execute().getItems();
if (list != null) {
//DO SOMETHING
}
}
}
請幫我。
在此先感謝。
使用上面的代碼,我得到java.lang.NullPointerException。 – user672009 2013-11-21 00:51:25