No default noargument constructor

When I follow the tutorial and docs on saving an object… all I get is the error message about there being ‘No default noargument constructor’. What does this mean?

BackendlessFault{ code: ‘IllegalArgumentException’, message: ‘No default noargument constructor’ }

    // Save object asynchronously...
    Backendless.Persistence.save( contact, new AsyncCallback<Contact>() {


        public void handleResponse( Contact response ) {
            Log.i(TAG, "Contact saved: " + response.getName());
        }


        public void handleFault( BackendlessFault fault ) {
            Log.i(TAG, "Contact failed to save : " + fault.toString());
        }
    });

Hi Kevin,

The error means that any "data object" class you use must have the default no-argument constructor. For example, the Contact class must have the following:


public class Contact
{
  public Contact()
  {
  }
}

The constructor is automatically generated by the compiler, unless you declared your own constructor (with arguments). In that case, the constructor without arguments must be added explicitly.

Regards,
Mark

Yes, this was the first thing I tried, but adding a no arg constructor didn’t fix the issue. Also, according to docs, this is not stated as a requirement.

https://backendless.com/documentation/data/android/data_saving_data_objects.htm

I’ve attached my sample project if it helps any. Note that I switched my sample from the more complicated Contact example in the docs back to the Comment class in the getting started guide.

Kevin

BackendlessTest.zip (1.6MB)

Kevin,

it is described in the documentation: https://backendless.com/documentation/data/android/data_data_object.htm

The reason you’re experiencing a problem is the Comment class is declared within the MainActivity class. Please make sure you’re not using inner classes to represent persistent data objects.

Regards,
Mark

Ok, that worked. Thanks!

Maybe a note about this should be added to the quick start guide. Most of the code snippets are shown separately without context. When it said create a Comment class, I just copied into my MainActivity as an inner class.

https://backendless.com/mobile-developers/quick-start-guide-for-android/

Also, providing a sample based on the guide steps to download would be helpful here.

Kevin