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

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -