java - Getting class cast exception while using android.support.v7.widget.SearchView -


i using menu show search icon on action bar. have create search view

itemsearch = menu.finditem(r.id.action_search_chat_home_container); searchview = (searchview) menuitemcompat.getactionview(itemsearch); 

i using android-support-v7-appcompat library project .

xml menu...

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:homecontainer="http://schemas.android.com/apk/res-auto" >    <item     android:id="@+id/action_search_chat_home_container"     android:icon="@drawable/ic_action_search"     android:title="@string/action_search"     homecontainer:showasaction="ifroom|collapseactionview"     homecontainer:actionviewclass="android.support.v7.widget.searchview"/>  </menu> 

i getting following error

*03-18 12:19:46.965 e/com.abc.contactbook.rtcontactbookactivity<======(14993): java.lang.classcastexception: android.support.v7.internal.view.menu.menuitemwrapperics$collapsibleactionviewwrapper cannot cast android.support.v7.widget.searchview 03-18 12:19:46.965 e/com.abc.contactbook.rtcontactbookactivity<======(14993):   @ com.abc.contactbook.rtcontactbookactivity.oncreateoptionsmenu(rtcontactbookactivity.java:874) 03-18 12:19:46.965 e/com.abc.contactbook.rtcontactbookactivity<======(14993):   @ android.support.v4.app.fragment.performcreateoptionsmenu(fragment.java:1560) 03-18 12:19:46.965 e/com.abc.contactbook.rtcontactbookactivity<======(14993):   @ android.support.v4.app.fragmentmanagerimpl.dispatchcreateoptionsmenu(fragmentmanager.java:1949) 03-18 12:19:46.965 e/com.abc.contactbook.rtcontactbookactivity<======(14993):   @ android.support.v4.app.fragment.performcreateoptionsmenu(fragment.java:1563) 03-18 12:19:46.965 e/com.rancore.contactbook.rtcontactbookactivity<======(14993):   @ android.support.v4.app.fragmentmanagerimpl.dispatchcreateoptionsmenu(fragmentmanager.java:1949) 03-18 12:19:46.965 e/com.abc.contactbook.rtcontactbookactivity<======(14993):   @ android.support.v4.app.fragmentactivity.oncreatepanelmenu(fragmentactivity.java:225) 03-18 12:19:46.965 e/com.abc.contactbook.rtcontactbookactivity<======(14993):   @ android.support.v7.app.actionbaractivity.superoncreatepanelmenu(actionbaractivity.java:224) 03-18 12:19:46.965 e/com.abc.contactbook.rtcontactbookactivity<======(14993):   @ android.support.v7.app.actionbaractivitydelegateics.oncreatepanelmenu(actionbaractivitydelegateics.java:141) 03-18 12:19:46.965 e/com.abc.contactbook.rtcontactbookactivity<======(14993):   @ android.support.v7.app.actionbaractivity.oncreatepanelmenu(actionbaractivity.java:199) 03-18 12:19:46.965 e/com.abc.contactbook.rtcontactbookactivity<======(14993):   @ android.support.v7.app.actionbaractivitydelegateics$windowcallbackwrapper.oncreatepanelmenu(actionbaractivitydelegateics.java:280) 03-18 12:19:46.965 e/com.abc.contactbook.rtcontactbookactivity<======(14993):   @ com.android.internal.policy.impl.phonewindow.preparepanel(phonewindow.java:455) 

code import packages in java file

import android.support.v4.view.menuitemcompat; import android.support.v7.app.actionbar; import android.support.v7.widget.searchview; import android.support.v7.widget.searchview.onquerytextlistener; 

can please try following lines of code?

itemsearch = menu.finditem(r.id.action_search_chat_home_container); searchview = (searchview) menuitemcompat.getactionview(itemsearch).getwrappedview(); 

source link

line 414.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -