android - AutoCompleteTextView with SimpleCursorAdapter return NullPointerException on filtering -
i have autocompletetextview have linked simplecursoradapter . working fine , when user input characters not in database , filtering method returns null cursor. cause non-fatal nullpointerexception. code is
madapter.setfilterqueryprovider(new filterqueryprovider() { @override public cursor runquery(charsequence constraint) { string partial = null; if(constraint!=null) partial = constraint.tostring(); cursor result= dbhelper.readproductcategory(partial); return result; } });
warning in logcat
w/filter﹕ exception occured during performfiltering()! java.lang.nullpointerexception @ com.orderoapp.ordero.data.productdatabasehelper.readproductcategory(productdatabasehelper.java:70) @ com.orderoapp.ordero.ordersfragment$1.runquery(ordersfragment.java:87) @ android.support.v4.widget.cursoradapter.runqueryonbackgroundthread(cursoradapter.java:397) @ android.support.v4.widget.cursorfilter.performfiltering(cursorfilter.java:50) @ android.widget.filter$requesthandler.handlemessage(filter.java:234) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:136) @ android.os.handlerthread.run(handlerthread.java:61)
i don't know in case of null cursor. should return null ? best way handle this. when user delete text in autocompletetextview , got error
e/spannablestringbuilder﹕ span_exclusive_exclusive spans cannot have 0 length
any ideas? gladly appreciate help. thanks.
the error due if statement in
productdatabasehelper.readproductcategory
method. if condition was
if ( con.length() > 0 ) { result = getreadabledatabase().query(productentry.table_name, projection, .... }
so when con null , gives nullpointerexception . solution simple . before checking if con.length() >0 , check if con not null.
if ( con!=null && con.length() > 0 ) { ... }
Comments
Post a Comment