java - Android Filter searchView Widget for scala " got ClassCastException" -
i want create "searchview widget" android in scala plugin eclipse, here code,
override def getfilter(): filter = { new filter() { protected override def publishresults(constraint: charsequence, results: filterresults) { var books = results.values.asinstanceof[list[bookmetadata]] itemadapter.this.notifydatasetchanged() } protected override def performfiltering(constraint: charsequence): filterresults = { val filteredresults = listbuffer(books.asscala.tolist.filter(b => b.tostring.startswith(constraint.tostring)): _*) .asinstanceof[list[bookmetadata]] val results = new filterresults() results.values = filteredresults results } } }
i don't have error when run program have classcastexception
here log:
08-23 13:37:06.986: v/bookfragment(25407): query : modern 08-23 13:37:06.996: w/filter(25407): exception occured during performfiltering()! 08-23 13:37:06.996: w/filter(25407): java.lang.classcastexception: scala.collection.mutable.listbuffer cannot cast java.util.list 08-23 13:37:06.996: w/filter(25407): @ com.bitlit.android.booksfragment$itemadapter$$anon$2. performfiltering(booksfragment.scala:138) 08-23 13:37:06.996: w/filter(25407): @ android.widget.filter$requesthandler.handlemessage(filter.java:234) 08-23 13:37:06.996: w/filter(25407): @ android.os.handler.dispatchmessage(handler.java:99) 08-23 13:37:06.996: w/filter(25407): @ android.os.looper.loop(looper.java:137) 08-23 13:37:06.996: w/filter(25407): @ android.os.handlerthread.run(handlerthread.java:61)
would please give me hints implementation
thanks in advance!
looking @ trace seems line causing issue one:
val filteredresults = listbuffer(books.asscala.tolist.filter(b => b.tostring.startswith(constraint.tostring)): _*) .asinstanceof[list[bookmetadata]]
you're doing this:
val filteredresults = listbuffer(meta1, meta2).asinstanceof[list[bookmetadata]]
so listbuffer[bookmetadata]
not instance of list[bookmetadata]
. case regardless of if mean java.util.list
or scala immutable list
.
you can this:
import collection.javaconverters._ val filteredresults = listbuffer(/* ... */).asjava // should return instance of java.util.list
Comments
Post a Comment