1
我想從後端數據庫表中檢索一個對象。其中稱「類別」與此有關係。 這是一對多關係,在用戶表中稱爲「類別」。 我真的嘗試了一切......我不知道問題出在哪裏..請幫助我! 我得到這個致命異常:試圖從後端檢索對象,但我得到致命的異常
FATAL EXCEPTION:main
BackendlessException{ code: 'Internal client exception', message: 'null' }
分類等級:
package com.backendless.celkituzes_app.data;
import com.backendless.Backendless;
import com.backendless.BackendlessCollection;
import com.backendless.BackendlessUser;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.geo.GeoPoint;
import com.backendless.persistence.BackendlessDataQuery;
public class Category
{
private String objectId;
private java.util.Date created;
private String categoryTitle;
private Boolean bonus;
private String ownerId;
private java.util.Date updated;
private java.util.List<BackendlessUser> subscribers;
public String getObjectId()
{
return objectId;
}
public java.util.Date getCreated()
{
return created;
}
public String getCategoryTitle()
{
return categoryTitle;
}
public void setCategoryTitle(String categoryTitle)
{
this.categoryTitle = categoryTitle;
}
public Boolean getBonus()
{
return bonus;
}
public void setBonus(Boolean bonus)
{
this.bonus = bonus;
}
public String getOwnerId()
{
return ownerId;
}
public java.util.Date getUpdated()
{
return updated;
}
public java.util.List<BackendlessUser> getSubscribers()
{
return subscribers;
}
public void setSubscribers(java.util.List<BackendlessUser> subscribers)
{
this.subscribers = subscribers;
}
public Category save()
{
return Backendless.Data.of(Category.class).save(this);
}
public Future<Category> saveAsync()
{
if(Backendless.isAndroid())
{
throw new UnsupportedOperationException("Using this method is restricted in Android");
}
else
{
Future<Category> future = new Future<Category>();
Backendless.Data.of(Category.class).save(this, future);
return future;
}
}
public void saveAsync(AsyncCallback<Category> callback)
{
Backendless.Data.of(Category.class).save(this, callback);
}
public Long remove()
{
return Backendless.Data.of(Category.class).remove(this);
}
public Future<Long> removeAsync()
{
if(Backendless.isAndroid())
{
throw new UnsupportedOperationException("Using this method is restricted in Android");
}
else
{
Future<Long> future = new Future<Long>();
Backendless.Data.of(Category.class).remove(this, future);
return future;
}
}
public void removeAsync(AsyncCallback<Long> callback)
{
Backendless.Data.of(Category.class).remove(this, callback);
}
public static Category findById(String id)
{
return Backendless.Data.of(Category.class).findById(id);
}
public static Future<Category> findByIdAsync(String id)
{
if(Backendless.isAndroid())
{
throw new UnsupportedOperationException("Using this method is restricted in Android");
}
else
{
Future<Category> future = new Future<Category>();
Backendless.Data.of(Category.class).findById(id, future);
return future;
}
}
public static void findByIdAsync(String id, AsyncCallback<Category> callback)
{
Backendless.Data.of(Category.class).findById(id, callback);
}
public static Category findFirst()
{
return Backendless.Data.of(Category.class).findFirst();
}
public static Future<Category> findFirstAsync()
{
if(Backendless.isAndroid())
{
throw new UnsupportedOperationException("Using this method is restricted in Android");
}
else
{
Future<Category> future = new Future<Category>();
Backendless.Data.of(Category.class).findFirst(future);
return future;
}
}
public static void findFirstAsync(AsyncCallback<Category> callback)
{
Backendless.Data.of(Category.class).findFirst(callback);
}
public static Category findLast()
{
return Backendless.Data.of(Category.class).findLast();
}
public static Future<Category> findLastAsync()
{
if(Backendless.isAndroid())
{
throw new UnsupportedOperationException("Using this method is restricted in Android");
}
else
{
Future<Category> future = new Future<Category>();
Backendless.Data.of(Category.class).findLast(future);
return future;
}
}
public static void findLastAsync(AsyncCallback<Category> callback)
{
Backendless.Data.of(Category.class).findLast(callback);
}
public static BackendlessCollection<Category> find(BackendlessDataQuery query)
{
return Backendless.Data.of(Category.class).find(query);
}
public static Future<BackendlessCollection<Category>> findAsync(BackendlessDataQuery query)
{
if(Backendless.isAndroid())
{
throw new UnsupportedOperationException("Using this method is restricted in Android");
}
else
{
Future<BackendlessCollection<Category>> future = new Future<BackendlessCollection<Category>>();
Backendless.Data.of(Category.class).find(query, future);
return future;
}
}
public static void findAsync(BackendlessDataQuery query, AsyncCallback<BackendlessCollection<Category>> callback)
{
Backendless.Data.of(Category.class).find(query, callback);
}
}
CategoryActivity:
package sgtt.celtkituzes_0_1;
import...
public class CategoryActivity extends AppCompatActivity {
String[] category = {"Általános jó közérzet","Táplálkozás és egészség","Fittség","Család","Kapcsolatok","Szabadidő","Karrier","Személyes fejlődés","Saját kihívások"};
SharedPreferences msgPreferences;
SharedPreferences.Editor msgPreferencesEditor;
private Boolean fclick;
public SharedPreferences loginPreferences;
public SharedPreferences.Editor loginPrefsEditor;
String password;
BackendlessUser backendlessUser= Backendless.UserService.CurrentUser();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_category);
Backendless.initApp(this,"19F954A6-2211-7ED0-FF1B-BD05FFD80200", "F445C642-63BF-0D19-FFBB-B06809011C00","v1");
// BackendlessCollection<Category> collection = Backendless.Data.of(Category.class).find();
final ListView CategorylistView = (ListView) findViewById(R.id.CategorylistView);
msgPreferences = getSharedPreferences("msgPref", MODE_PRIVATE);
msgPreferencesEditor = msgPreferences.edit();
fclick = msgPreferences.getBoolean("msgPref", false);
loginPreferences = getSharedPreferences("LoginPrefs", MODE_PRIVATE);
loginPrefsEditor = loginPreferences.edit();
ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,category);
CategorylistView.setAdapter(adapter);
CategorylistView.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,category){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView textView = (TextView) super.getView(position, convertView, parent);
if (position > 1) {
textView.setTextColor(0xffcccccc);
}
if(position <2){
textView.setTextSize(24);
textView.setTypeface(null, Typeface.BOLD);
}
return textView;
}
});
CategorylistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView,View view, int i, long l) {
final String category = (String) adapterView.getItemAtPosition(i);
BackendlessDataQuery query = new BackendlessDataQuery();
query.setWhereClause("objectId = '8A2BC69E-0894-965F-FF45-B82C60BBEB00'");
//the problem is here i think..
BackendlessCollection<Category> cat1 = Backendless.Persistence.of(Category.class).find(query);
if(i==0){
backendlessUser.setProperty("categories",cat1);
}
if(i==1){
}
if(i==2){
}
if(i==3){
}
if(i==4){
}
if(i==5){
}
if(i==6){
}
if(i==7){
}
if(i==8) {
}
}
});
}
}
您可能會檢查並提供[mcve],您的代碼太長。 – Prisoner