【发布时间】:2014-09-12 02:59:04
【问题描述】:
我的项目 (https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial) 已按照此教程进行操作,一切正常。
但是当我想为我的实体使用 objectify 类时,它不起作用,我无法使用我的 android 应用程序检索数据存储区中的数据!
例如,使用该代码没关系,我可以从我的 android 应用程序中恢复我的用户:
import javax.jdo.annotations.Index;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
@Index
public class Utilisateur {
//Nos variables de classes
@Id String num_portable; //Clé pour notre entité NOTION CLE PRIMAIRE String car c'est à nous de le définir.
Boolean sexe;
int date_naissance;
String position_geo;
String liste_contact;
Boolean blacklistage;
//Constructeur par défaut (Obligatoire pour Objectify)
private Utilisateur(){}
public Utilisateur (String num_portable, Boolean sexe, int date_naissance, String position_geo, String liste_contact, Boolean blacklistage) {
this.num_portable=num_portable;
this.sexe=sexe;
this.date_naissance=date_naissance;
this.position_geo=position_geo;
this.liste_contact=liste_contact;
this.blacklistage=blacklistage;
}
public String getNum_portable() {
return num_portable;
}
}
但我不使用 Objectify.. 当我想使用 Objectify 时,使用该代码,它不起作用: 我只是替换这段代码:
import javax.jdo.annotations.Index;
import javax.persistence.Entity;
import javax.persistence.Id;
有了这个:
import com.googlecode.objectify.annotation.Entity;
import com.googlecode.objectify.annotation.Id;
import com.googlecode.objectify.annotation.Index;
我在我的应用引擎上收到此错误:
com.google.api.server.spi.SystemService invokeServiceMethod: Class Utilisateur for query has not been resolved. Check the query and any imports/aliases specification
javax.persistence.PersistenceException: Class Utilisateur for query has not been resolved. Check the query and any imports/aliases specification
所以我的问题是:我们能否将 Objectify 与 Android 应用程序一起使用,或者数据持久性不适用于它(和 App Engine)?
编辑:这是我在调用后端的 Android 应用程序上的代码(与此处的代码相同 => https://cloud.google.com/developers/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial):
public class JeveuxvoirActivity extends Activity {
private ListView utilisateursList;
private List<Utilisateur> utilisateurs = null;
//Création de notre activité
public void onCreate(Bundle savedInstanceState) {
//Création de notre interface graphique
super.onCreate(savedInstanceState);
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//On définit le Layout de notre activité
setContentView(R.layout.activity_jeveuxvoir);
utilisateursList = (ListView) findViewById(R.id.list_principal_user);
// start retrieving the list of nearby places
new ListOfUtilisateursAsyncRetriever().execute();
}
//*******************************************************
// FONCTIONS ASYNC
//*******************************************************
/**
* AsyncTask for retrieving the list of places (e.g., stores) and updating the
* corresponding results list.
*/
private class ListOfUtilisateursAsyncRetriever extends AsyncTask<Void, Void, CollectionResponseUtilisateur> {
@Override
protected CollectionResponseUtilisateur doInBackground(Void... params) {
Utilisateurendpoint.Builder endpointBuilder = new Utilisateurendpoint.Builder(
AndroidHttp.newCompatibleTransport(), new JacksonFactory(), null);
endpointBuilder = CloudEndpointUtils.updateBuilder(endpointBuilder);
CollectionResponseUtilisateur result;
Utilisateurendpoint endpoint = endpointBuilder.build();
try {
result = endpoint.listUtilisateur().execute();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result = null;
}
return result;
}
@Override
@SuppressWarnings("null")
protected void onPostExecute(CollectionResponseUtilisateur result) {
ListAdapter utilisateursListAdapter = createUtilisateurListAdapter(result.getItems());
utilisateursList.setAdapter(utilisateursListAdapter);
utilisateurs = result.getItems();
}
}
private ListAdapter createUtilisateurListAdapter(List<Utilisateur> utilisateurs) {
List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
for (Utilisateur utilisateur : utilisateurs) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("utilisateurIcon", R.drawable.ic_launcher);
map.put("utilisateurPort", utilisateur.getNumPortable());
data.add(map);
}
SimpleAdapter adapter = new SimpleAdapter(JeveuxvoirActivity.this, data, R.layout.utilisateur_item,
new String[] {"utilisateurIcon", "utilisateurPort"},
new int[] {R.id.utilisateur_Icon, R.id.utilisateur_port});
return adapter;
}
【问题讨论】:
-
您好,Objectify 专为 AppEngine Datastore 设计,因此无论您如何访问端点(Android、webapp 等),它都应该可以工作。您能否提供代码 sn-p 进行对象化查询?
-
另外,为了确定,您是否通过 Objectify 注册了您的班级
Utilisateur?见code.google.com/p/objectify-appengine/wiki/…
标签: android google-app-engine google-cloud-endpoints objectify google-cloud-datastore