Search code examples
androidandroid-actionbaractionbarsherlock

ActionbarSherlock search widget throwing ClassNotFoundException


I have a searchView widget implemented using actionbarSherlock. My onCreateOptionsMenu looks like this :

@Override
    public boolean onCreateOptionsMenu(Menu menu) {

        searchView = new SearchView(getSupportActionBar().getThemedContext());
        searchView.setQueryHint("Search for movies to reco");
        searchView.setOnQueryTextListener(this);
        searchView.setOnSuggestionListener(this);

        menu.add(Menu.NONE, RECO_MENU_ITEM_ID, Menu.NONE, "Search for Something")
            .setIcon(R.drawable.ic_action_search)
            .setActionView(searchView)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

        menu.findItem(RECO_MENU_ITEM_ID);

        setMenu(menu);

        return true;
    }

For some reason, at the first line of creation, it throws a this exception :

com.talkiesapp fatal error : com.actionbarsherlock.R$layout
java.lang.NoClassDefFoundError: com.actionbarsherlock.R$layout
    at com.actionbarsherlock.widget.SearchView.<init>(SearchView.java:264)
    at com.actionbarsherlock.widget.SearchView.<init>(SearchView.java:252)
    at com.myapp.MainActivity.onCreateOptionsMenu(MainActivity.java:162)

It was working perfectly earlier, I may have done some change which is causing this failure. ActionBarSherlock is been used as a Library in my project.

Thanks


Solution

  • You can build an clean your project your project to recreate the R.class of ActionBarSherlock