Search code examples
backendless

What is the reason of 'Internal client exception' in Backendless?


I have table Task : enter image description here

I want to get records in this table. But there is an BackendlessException { code: 'Internal client exception', message: 'null' }

Here is my code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_task);

    Backendless.initApp(getApplicationContext() ,APP_ID, SECRET_KEY, VERSION);


    BackendlessCollection<Task> tasks = Backendless.Data.of(Task.class).find();

    System.out.println( "Size " + tasks.getCurrentPage().size() );


    Iterator<Task> iterator = tasks.getCurrentPage().iterator();

    while (iterator.hasNext())
    {
        Task t = iterator.next();
        System.out.println("Question = " + t.getQuestion());
        System.out.println("Answer =  " + t.getAnswer());
    }





}

Task.class:

   public class Task {
    public String Question ;
    public  String Answer ;
    public  String ownerId ;
    public    String objectId ;
    public   Date created ;
    public Date updated ;
    public Task()
    {

    }
    public Task(String Question ,String Answer)
    {
        this.Question = Question ;
        this.Answer = Answer ;

    }




}

I learned this query from Backendless documentation. What is the reason of this error? How to avoid from this error? Are there some rules to know before retrieving data from Backedless?


Solution

  • You're invoking a synchronous (blocking) API on the main UI thread right here:

    BackendlessCollection<Task> tasks = Backendless.Data.of(Task.class).find();
    

    To avoid the error, either create a separate thread and use the API in there, or change the call to the asynchronous version.

    The API documentation says:

    Android applications cannot use synchronous APIs on the main UI thread. The reason for this is the main thread does not allow blocking calls. Since the API requests perform network-based communication, the naturally block. As a result, when using the Backendless APIs make sure to use the asynchronous version of the methods, or create a new thread and use the synchronous API in it