android - App crashes when insert new data with ContentProvider -


this code:

for insert of contentprovider :

public uri insert(uri uri, contentvalues contentvalues) {      final int match = surimatcher.match(uri);     switch (match) {         case dog:             insertdog(uri, contentvalues);         default:             throw new illegalargumentexception("insertion not supported " + uri);     } }  private uri insertdog(uri uri, contentvalues contentvalues) {      sqlitedatabase db = mdbhelper.getwritabledatabase();     long id = db.insert(dogentry.table_name, null, contentvalues);     if (id == -1) {         log.e(log_tag, "failed insert row " + uri);         return null;     }     return contenturis.withappendedid(uri, id); } 

this insert data:

    contentvalues values = new contentvalues();     values.put(dogentry.name, "doggy");     values.put(dogentry.breed, "dingo");     values.put(dogentry.gender, dogentry.gender_male);     values.put(dogentry.weight, 15);     uri newuri = getcontentresolver().insert(dogentry.content_uri,values); 

note: constants defined in contract class.

you forget return:

... case dog:      return insertdog(uri, contentvalues); 

explanations: switch goes through cases , default @ end. should call break or return in case statements.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -