试图从后端检索对象,但出现致命异常
Trying to retrieve object from backendless, but i get fatal exception
我想从后端数据库 table 中检索一个对象。调用 "Category" 与此建立关系。
这是一个一对多的关系,在 Users table 中称为 "categories"。
我真的什么都试过了...我不知道问题出在哪里..请帮帮我!
我遇到了这个致命异常:
FATAL EXCEPTION:main
BackendlessException{ code: 'Internal client exception', message: 'null' }
类别class:
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 );
}
}
类别活动:
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) {
}
}
});
}
}
现在可以使用了!我只需要使用异步方法。
if(i==0){
Backendless.Persistence.of(Category.class).findById("8A2BC69E-0894-965F-FF45-B82C60BBEB00", new AsyncCallback<Category>() {
@Override
public void handleResponse(Category response) {
final Category cat1 = response;
Toast.makeText(getApplicationContext(),"Done",Toast.LENGTH_SHORT).show();
Backendless.UserService.login( email, password, new AsyncCallback<BackendlessUser>()
{
@Override
public void handleResponse( BackendlessUser backendlessUser )
{
backendlessUser.setProperty("categories",cat1);
Backendless.UserService.update(backendlessUser, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser response) {
System.out.println( "User has been updated" );
}
@Override
public void handleFault(BackendlessFault fault) {
}
});
Toast.makeText(getApplicationContext(), "Done!", Toast.LENGTH_SHORT).show();
}
@Override
public void handleFault( BackendlessFault backendlessFault )
{
System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
}
} );
}
@Override
public void handleFault(BackendlessFault fault) {
}
});
}
我想从后端数据库 table 中检索一个对象。调用 "Category" 与此建立关系。 这是一个一对多的关系,在 Users table 中称为 "categories"。 我真的什么都试过了...我不知道问题出在哪里..请帮帮我! 我遇到了这个致命异常:
FATAL EXCEPTION:main
BackendlessException{ code: 'Internal client exception', message: 'null' }
类别class:
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 );
}
}
类别活动:
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) {
}
}
});
}
}
现在可以使用了!我只需要使用异步方法。
if(i==0){
Backendless.Persistence.of(Category.class).findById("8A2BC69E-0894-965F-FF45-B82C60BBEB00", new AsyncCallback<Category>() {
@Override
public void handleResponse(Category response) {
final Category cat1 = response;
Toast.makeText(getApplicationContext(),"Done",Toast.LENGTH_SHORT).show();
Backendless.UserService.login( email, password, new AsyncCallback<BackendlessUser>()
{
@Override
public void handleResponse( BackendlessUser backendlessUser )
{
backendlessUser.setProperty("categories",cat1);
Backendless.UserService.update(backendlessUser, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser response) {
System.out.println( "User has been updated" );
}
@Override
public void handleFault(BackendlessFault fault) {
}
});
Toast.makeText(getApplicationContext(), "Done!", Toast.LENGTH_SHORT).show();
}
@Override
public void handleFault( BackendlessFault backendlessFault )
{
System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
}
} );
}
@Override
public void handleFault(BackendlessFault fault) {
}
});
}