android - Why everytime I click on delete chat message the app stop working? -
every time when click on delete chat message, app stop working. did check code based on errors got i'm still not sure what's wrong code.
@override public boolean onoptionsitemselected(menuitem item) { switch (item.getitemid()) { case r.id.action_delete: getcontentresolver().delete(uri.withappendedpath(contentprovider.content_uri_messages_chat, profilechatid), null, null); getcontentresolver().delete(uri.withappendedpath(contentprovider.content_uri_profile, profileid), null, null); finish(); return super.onoptionsitemselected(item); }
below chat menu layout.
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:id="@+id/action_delete" android:showasaction="always" android:icon="@android:drawable/ic_menu_delete" android:title="@string/delete_chat"/> </menu>
these errors get.
java.lang.illegalargumentexception: unsupported uri: content://com.example.app.provider/messages/chat/ @ com.example.app.dataprovider.delete(dataprovider.java:189) @ android.content.contentprovider$transport.delete(contentprovider.java:273) @ android.content.contentresolver.delete(contentresolver.java:1282) @ com.example.app.chatactivity.onoptionsitemselected(chatactivity.java:158) @ android.app.activity.onmenuitemselected(activity.java:2600) @ android.support.v4.app.fragmentactivity.onmenuitemselected(fragmentactivity.java:350) @ com.android.internal.policy.impl.phonewindow.onmenuitemselected(phonewindow.java:1012) @ com.android.internal.view.menu.menubuilder.dispatchmenuitemselected(menubuilder.java:742) @ com.android.internal.view.menu.menuitemimpl.invoke(menuitemimpl.java:152) @ com.android.internal.view.menu.menubuilder.performitemaction(menubuilder.java:881) @ com.android.internal.view.menu.actionmenuview.invokeitem(actionmenuview.java:546) @ com.android.internal.view.menu.actionmenuitemview.onclick(actionmenuitemview.java:115) @ android.view.view.performclick(view.java:4438) @ android.view.view$performclick.run(view.java:18422) @ android.os.handler.handlecallback(handler.java:733) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5017) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:779) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:595) @ dalvik.system.nativestart.main(native method)
data provider.java
@override public int delete(uri uri, string selection, string[] selectionargs) { sqlitedatabase db = dbhelper.getwritabledatabase(); int count; switch(urimatcher.match(uri)) { case messages_allrows: count = db.delete(table_messages, selection, selectionargs); break; case messages_single_row: count = db.delete(table_messages, "_id = ?", new string[]{uri.getlastpathsegment()}); break; case profile_allrows: count = db.delete(table_profile, selection, selectionargs); break; case profile_single_row: count = db.delete(table_profile, "_id = ?", new string[]{uri.getlastpathsegment()}); break; case messages_chat_row: count = db.delete(table_messages, "to_cid = ? or ( from_cid = ? , to_cid = ?)", new string[]{uri.getlastpathsegment(),uri.getlastpathsegment(), common.getchatid()}); log.d("count del", ""+count); break; default: throw new illegalargumentexception("unsupported uri: " + uri); } contentresolver cr = getcontext().getcontentresolver(); cr.notifychange(uri, null); return count; }
Comments
Post a Comment