Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Search View Widget Crashes in ICS and above #685

Closed
jcampbell05 opened this Issue · 68 comments
@jcampbell05

When using the Search View Widget as a Action View in the latest sherlock with Ice Cream Sandwich or above it crashes complaining about a layout file.

I've fixed it by setting the code in my activity that uses a plain button for Eclair (As google recommends), The sherlock implementation from Froyo to Honeycomb and then the native one from Ice Cream Upwards.

I think the Sherlock Implementation should wrap around the native widget by default or is this not possible ? At least it should throw an error complaining it isn't compatible with anything newer than Honeycomb and the user should use the Native Widget

@JakeWharton
Owner

Stack trace? Example code? Demo project?

It works on all APIs using the example in the 'demos' sample app.

@jcampbell05

This is the error I got.

11-03 00:50:22.587: E/AndroidRuntime(928): FATAL EXCEPTION: main
11-03 00:50:22.587: E/AndroidRuntime(928): android.view.InflateException: Binary XML file line #29: Error inflating class
11-03 00:50:22.587: E/AndroidRuntime(928): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
11-03 00:50:22.587: E/AndroidRuntime(928): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-03 00:50:22.587: E/AndroidRuntime(928): at com.actionbarsherlock.widget.SearchView.(SearchView.java:264)
11-03 00:50:22.587: E/AndroidRuntime(928): at com.actionbarsherlock.widget.SearchView.(SearchView.java:252)
11-03 00:50:22.587: E/AndroidRuntime(928): at com.NYXDigital.LookBunnyFind.Activities.LookBunnyFindActivity.onCreateOptionsMenu(LookBunnyFindActivity.java:63)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.support.v4.app.Watson.onCreatePanelMenu(Watson.java:45)
11-03 00:50:22.587: E/AndroidRuntime(928): at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:559)
11-03 00:50:22.587: E/AndroidRuntime(928): at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSherlockNative.java:60)
11-03 00:50:22.587: E/AndroidRuntime(928): at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(SherlockFragmentActivity.java:165)
11-03 00:50:22.587: E/AndroidRuntime(928): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:388)
11-03 00:50:22.587: E/AndroidRuntime(928): at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:739)
11-03 00:50:22.587: E/AndroidRuntime(928): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:2833)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.os.Handler.handleCallback(Handler.java:605)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.os.Handler.dispatchMessage(Handler.java:92)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.os.Looper.loop(Looper.java:137)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.app.ActivityThread.main(ActivityThread.java:4424)
11-03 00:50:22.587: E/AndroidRuntime(928): at java.lang.reflect.Method.invokeNative(Native Method)
11-03 00:50:22.587: E/AndroidRuntime(928): at java.lang.reflect.Method.invoke(Method.java:511)
11-03 00:50:22.587: E/AndroidRuntime(928): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-03 00:50:22.587: E/AndroidRuntime(928): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-03 00:50:22.587: E/AndroidRuntime(928): at dalvik.system.NativeStart.main(Native Method)
11-03 00:50:22.587: E/AndroidRuntime(928): Caused by: java.lang.reflect.InvocationTargetException
11-03 00:50:22.587: E/AndroidRuntime(928): at java.lang.reflect.Constructor.constructNative(Native Method)
11-03 00:50:22.587: E/AndroidRuntime(928): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
11-03 00:50:22.587: E/AndroidRuntime(928): ... 25 more
11-03 00:50:22.587: E/AndroidRuntime(928): Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x7f01002b a=-1}
11-03 00:50:22.587: E/AndroidRuntime(928): at android.content.res.Resources.loadColorStateList(Resources.java:2040)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.widget.TextView.(TextView.java:774)
11-03 00:50:22.587: E/AndroidRuntime(928): at android.widget.TextView.(TextView.java:442)
11-03 00:50:22.587: E/AndroidRuntime(928): ... 28 more

@jcampbell05

And here is the code that triggered it

```package com.NYXDigital.LookBunnyFind.Activities;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.widget.SearchView;
import com.NYXDigital.LookBunnyFind.Adapters.FragmentViewPagerAdapter;
import com.NYXDigital.LookBunnyFind.Fragments.BranchListFragment;
import com.NYXDigital.LookBunnyFind.Fragments.FindFragment;
import com.NYXDigital.LookBunnyFind.Widget.FragmentViewPagerItem;
import com.viewpagerindicator.*;

public class LookBunnyFindActivity extends SherlockFragmentActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // Create adapter for pager and add fragments to be displayed
    FragmentViewPagerAdapter adapter = new FragmentViewPagerAdapter(
            getSupportFragmentManager());

    // Local
    FragmentViewPagerItem localFragment = new FragmentViewPagerItem(
            "Local", new BranchListFragment());
    adapter.addFragment(localFragment);

    // Find
    FragmentViewPagerItem findFragment = new FragmentViewPagerItem("Find",
            new FindFragment());
    adapter.addFragment(findFragment);

    // Events
    FragmentViewPagerItem eventsFragment = new FragmentViewPagerItem(
            "Events", new BranchListFragment());
    adapter.addFragment(eventsFragment);

    // Set the pager with an adapter
    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(adapter);

    // Bind the title indicator to the adapter
    TabPageIndicator mIndicator = (TabPageIndicator) findViewById(R.id.indicator);
    mIndicator.setViewPager(pager);

}

public boolean onCreateOptionsMenu(Menu menu) {

    // Create the Search Menu Item
    MenuItem searchItem = menu.add("Search").setIcon(
            R.drawable.abs__ic_search);
    searchItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM
            | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    // Check Application is running on Android Froyo or Above
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.FROYO) {
        // Create the search view
        SearchView searchView = new SearchView(getSupportActionBar()
                .getThemedContext());
        searchView.setQueryHint("e.g Farm park");

        // Setup Action View
        searchItem.setActionView(searchView);

    }

    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {

    // If this is the search button then
    if (item.getTitle() == "Search") {
        this.onSearchRequested();
        return true;
    }

    return false;
}

}

@iNoles

@jcampbell05 android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x7f01002b a=-1}

@jcampbell05

What would cause that error ? Is that something in my code ?

@faridz

same thing, crash with JB 4.2; Works with Android 2.2 though.

@inktomi

We are also seeing a similar crash, though it only seems to effect a few devices. I cannot reproduce it myself, but users report that the app crashes right away.

    <item
    android:id="@+id/menu_search"
    android:icon="@drawable/ic_action_search_default"
    android:actionViewClass="com.actionbarsherlock.widget.SearchView"
    android:showAsAction="always|collapseActionView"
    android:menuCategory="system"
    android:orderInCategory="11"
    android:title="@string/menu_search"/>


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getSupportMenuInflater().inflate(R.menu.base_menu, menu);
    mSearchItem = menu.findItem(R.id.menu_search);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) mSearchItem.getActionView();
    if( null != mSearchView ){
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    }

    return true;
}

java.lang.RuntimeException: Unable to resume activity {com.zappos.android/com.zappos.android.activities.HomeActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x7f0d008e
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2634)
.......
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f0d008e
at android.content.res.Resources.getText(Resources.java:229)
at android.content.res.Resources.getString(Resources.java:313)
at android.content.Context.getString(Context.java:292)
at com.actionbarsherlock.widget.SearchView.updateQueryHint(SearchView.java:1090)
at com.actionbarsherlock.widget.SearchView.setSearchableInfo(SearchView.java:371)
at com.zappos.android.activities.BaseActivity.onCreateOptionsMenu(BaseActivity.java:176)
at com.zappos.android.activities.BaseCartActivity.onCreateOptionsMenu(BaseCartActivity.java:246)
at com.zappos.android.activities.HomeActivity.onCreateOptionsMenu(HomeActivity.java:323)
at android.support.v4.app.Watson.onCreatePanelMenu(Watson.java:45)
at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:559)
at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSherlockNative.java:60)
at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(SherlockFragmentActivity.java:165)
at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:393)
at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:747)
at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchInvalidateOptionsMenu(ActionBarSherlockNative.java:49)
at com.actionbarsherlock.app.SherlockFragmentActivity.invalidateOptionsMenu(SherlockFragmentActivity.java:150)
at com.zappos.android.activities.HomeActivity.onResume(HomeActivity.java:403)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)
at android.app.Activity.performResume(Activity.java:5132)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2617)

@esteluk

I don't think that this is a device related issue. I'm encountering the crash in my app, but the sample is running fine (Galaxy Nexus, 4.2.1 stock). I'll see if I can get a minimal testcase.

@esteluk

Ok, this looks like it's due to the Application Theme and theme inheritance.

@jcampbell05
@RobGThai

So, out of the blue I suddenly get this error. The app was building and running fine and suddenly this happen.

12-17 17:56:20.901: W/MenuInflater(11863): Cannot instantiate class: com.actionbarsherlock.widget.SearchView
12-17 17:56:20.901: W/MenuInflater(11863): java.lang.reflect.InvocationTargetException
12-17 17:56:20.901: W/MenuInflater(11863):  at java.lang.reflect.Constructor.constructNative(Native Method)
12-17 17:56:20.901: W/MenuInflater(11863):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.actionbarsherlock.view.MenuInflater$MenuState.newInstance(MenuInflater.java:488)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.actionbarsherlock.view.MenuInflater$MenuState.setItem(MenuInflater.java:447)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.actionbarsherlock.view.MenuInflater$MenuState.addItem(MenuInflater.java:468)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.actionbarsherlock.view.MenuInflater.parseMenu(MenuInflater.java:190)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.actionbarsherlock.view.MenuInflater.inflate(MenuInflater.java:112)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.mondial.thailand.rsa.fragment.MapFragment$SearchActionMode.onCreateActionMode(MapFragment.java:586)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.actionbarsherlock.internal.ActionBarSherlockNative$ActionModeCallbackWrapper.onCreateActionMode(ActionBarSherlockNative.java:233)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onCreateActionMode(PhoneWindow.java:2550)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.android.internal.app.ActionBarImpl$ActionModeImpl.dispatchOnCreate(ActionBarImpl.java:871)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.android.internal.app.ActionBarImpl.startActionMode(ActionBarImpl.java:446)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.app.Activity.onWindowStartingActionMode(Activity.java:4881)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2256)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.app.Activity.startActionMode(Activity.java:4864)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.actionbarsherlock.internal.ActionBarSherlockNative.startActionMode(ActionBarSherlockNative.java:211)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.actionbarsherlock.app.SherlockFragmentActivity.startActionMode(SherlockFragmentActivity.java:47)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.mondial.thailand.rsa.fragment.MapFragment.showActionMode(MapFragment.java:576)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.mondial.thailand.rsa.fragment.MapFragment.onClick(MapFragment.java:570)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.view.View.performClick(View.java:4202)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.view.View$PerformClick.run(View.java:17340)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.os.Handler.handleCallback(Handler.java:725)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.os.Handler.dispatchMessage(Handler.java:92)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.os.Looper.loop(Looper.java:137)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.app.ActivityThread.main(ActivityThread.java:5039)
12-17 17:56:20.901: W/MenuInflater(11863):  at java.lang.reflect.Method.invokeNative(Native Method)
12-17 17:56:20.901: W/MenuInflater(11863):  at java.lang.reflect.Method.invoke(Method.java:511)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-17 17:56:20.901: W/MenuInflater(11863):  at dalvik.system.NativeStart.main(Native Method)
12-17 17:56:20.901: W/MenuInflater(11863): Caused by: android.view.InflateException: Binary XML file line #29: Error inflating class <unknown>
12-17 17:56:20.901: W/MenuInflater(11863):  at android.view.LayoutInflater.createView(LayoutInflater.java:613)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.actionbarsherlock.widget.SearchView.<init>(SearchView.java:264)
12-17 17:56:20.901: W/MenuInflater(11863):  at com.actionbarsherlock.widget.SearchView.<init>(SearchView.java:252)
12-17 17:56:20.901: W/MenuInflater(11863):  ... 30 more
12-17 17:56:20.901: W/MenuInflater(11863): Caused by: java.lang.reflect.InvocationTargetException
12-17 17:56:20.901: W/MenuInflater(11863):  at java.lang.reflect.Constructor.constructNative(Native Method)
12-17 17:56:20.901: W/MenuInflater(11863):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.view.LayoutInflater.createView(LayoutInflater.java:587)
12-17 17:56:20.901: W/MenuInflater(11863):  ... 38 more
12-17 17:56:20.901: W/MenuInflater(11863): Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x7f01001f a=-1}
12-17 17:56:20.901: W/MenuInflater(11863):  at android.content.res.Resources.loadColorStateList(Resources.java:2074)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.widget.TextView.<init>(TextView.java:775)
12-17 17:56:20.901: W/MenuInflater(11863):  at android.widget.TextView.<init>(TextView.java:449)
12-17 17:56:20.901: W/MenuInflater(11863):  ... 41 more

R.menu.interactive_map

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:panel="http://schemas.android.com/apk/res-auto">
    <item android:id="@+id/action_search"
          android:title="@string/app_name"
          android:icon="@android:drawable/ic_menu_search"
          android:showAsAction="always"
          android:actionViewClass="com.actionbarsherlock.widget.SearchView" />
</menu>

This is placed inside a Fragment. ActionMode, Menu, and MenuInflater are all ABS.

private class SearchActionMode implements ActionMode.Callback{

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            Log.d(TAG, "onCreateActionMode creating inflater");
            MenuInflater inflater = new MenuInflater(getActivity());
            Log.d(TAG, "onCreateActionMode inflating"); // **Exception thrown after this line.**
            inflater.inflate(R.menu.interactive_map, menu); 
            Log.d(TAG, "onCreateActionMode finding SearchView");
            mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView();

            Log.d(TAG, "mSearchView: " + mSearchView);
            setupSearchView();
            return true;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            Log.d(TAG, "onPrepareActionMode");

            mSearchView.requestFocus();
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            Log.d(TAG, "onActionItemClicked");
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            Log.d(TAG, "onDestroyActionMode");
            closeTopTray();
            closeListView();
        }

    }
@PiusLT

I created an empty project and added just a single line to it to get the error:

SearchView searchView = new SearchView(getSupportActionBar().getThemedContext());

12-17 16:49:56.844: E/AndroidRuntime(12016): FATAL EXCEPTION: main
12-17 16:49:56.844: E/AndroidRuntime(12016): android.view.InflateException: Binary XML file line #29: Error inflating class
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.view.LayoutInflater.createView(LayoutInflater.java:606)
12-17 16:49:56.844: E/AndroidRuntime(12016): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
12-17 16:49:56.844: E/AndroidRuntime(12016): at com.actionbarsherlock.widget.SearchView.(SearchView.java:264)
12-17 16:49:56.844: E/AndroidRuntime(12016): at com.actionbarsherlock.widget.SearchView.(SearchView.java:252)
12-17 16:49:56.844: E/AndroidRuntime(12016): at com.example.testsearchview.MainActivity.onCreateOptionsMenu(MainActivity.java:23)
12-17 16:49:56.844: E/AndroidRuntime(12016): at com.actionbarsherlock.app.SherlockActivity.onCreatePanelMenu(SherlockActivity.java:184)
12-17 16:49:56.844: E/AndroidRuntime(12016): at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:559)
12-17 16:49:56.844: E/AndroidRuntime(12016): at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSherlockNative.java:60)
12-17 16:49:56.844: E/AndroidRuntime(12016): at com.actionbarsherlock.app.SherlockActivity.onCreateOptionsMenu(SherlockActivity.java:149)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.app.Activity.onCreatePanelMenu(Activity.java:2444)
12-17 16:49:56.844: E/AndroidRuntime(12016): at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:405)
12-17 16:49:56.844: E/AndroidRuntime(12016): at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:756)
12-17 16:49:56.844: E/AndroidRuntime(12016): at com.android.internal.policy.impl.PhoneWindow$1.run(PhoneWindow.java:2852)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.os.Handler.handleCallback(Handler.java:605)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.os.Handler.dispatchMessage(Handler.java:92)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.os.Looper.loop(Looper.java:137)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.app.ActivityThread.main(ActivityThread.java:4424)
12-17 16:49:56.844: E/AndroidRuntime(12016): at java.lang.reflect.Method.invokeNative(Native Method)
12-17 16:49:56.844: E/AndroidRuntime(12016): at java.lang.reflect.Method.invoke(Method.java:511)
12-17 16:49:56.844: E/AndroidRuntime(12016): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
12-17 16:49:56.844: E/AndroidRuntime(12016): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
12-17 16:49:56.844: E/AndroidRuntime(12016): at dalvik.system.NativeStart.main(Native Method)
12-17 16:49:56.844: E/AndroidRuntime(12016): Caused by: java.lang.reflect.InvocationTargetException
12-17 16:49:56.844: E/AndroidRuntime(12016): at java.lang.reflect.Constructor.constructNative(Native Method)
12-17 16:49:56.844: E/AndroidRuntime(12016): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
12-17 16:49:56.844: E/AndroidRuntime(12016): ... 26 more
12-17 16:49:56.844: E/AndroidRuntime(12016): Caused by: android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x7f01001f a=-1}
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.content.res.Resources.loadColorStateList(Resources.java:2044)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.content.res.TypedArray.getColorStateList(TypedArray.java:342)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.widget.TextView.(TextView.java:786)
12-17 16:49:56.844: E/AndroidRuntime(12016): at android.widget.TextView.(TextView.java:454)
12-17 16:49:56.844: E/AndroidRuntime(12016): ... 29 more

@jcampbell05
@SimonVT
Collaborator

Add a test case to the known-bugs project on the dev branch.

@RobGThai

Thanks to @esteluk and @Prototik. I fixed it by adding to v14 ofSherlock theme.

    <item name="textColorPrimary">@color/abs__primary_text_holo_light</item>
    <item name="textColorPrimaryInverse">@color/abs__primary_text_holo_dark</item>
@chinhnguyen

@RobGThai, can you please post an example? Your fix seems to not working on my side. Thanks.

@RobGThai

Basically, in res/values-v14/abs__themes.xml

Added those items to Sherlock.__Theme

<style name="Sherlock.__Theme" parent="android:Theme.Holo">
    <item name="textColorPrimary">@color/abs__primary_text_holo_light</item>
    <item name="textColorPrimaryInverse">@color/abs__primary_text_holo_dark</item>
</style>
@SimonVT
Collaborator

Both of those attributes are already defined in the Theme.Sherlock* themes.

@chinhnguyen

@RobGThai, thanks for the snippet. But it doesn't work on my side and I did follow the example code in your first post.

@RobGThai

@SimonVT TBH I don't know much about styling in Android. In this case when I debug the app it crashes on the TextView in the ActionBar and the textColorPrimary is the only thing on it. Adding these solved the problem that I had. Tested working on three other ICS/JB devices as well.

@chinhnguyen May be the root cause of your problem is different than mine, try debugging to scope down where the actual problem is that might help you find better answer.

@michaelye

I encountered this problem too.I copyed the "SampleList.java" in demos to my application,then setTheme(SampleList.THEME); in onCreate() method,and it works.

@JakeWharton
Owner

Still can't repro this on any device and we've never seen it in either Square application in the wild.

@jcampbell05
@JakeWharton
Owner

Well I'm certainly not going to be recommending that since I've seen it deployed without incident to hundreds of different devices.

@RobGThai

Could localization be part of the problem? I force my app to localize in Thai (th). Your demo app works fine on the same device tho. I didnt do anything fancy with the styling either.

@JakeWharton
Owner

I'm happy to try anything to reproduce the problem. I'll test different locales set on the phone with demos that only have certain ones specified.

@jcampbell05
@jcampbell05
@hahnjo

First, great thanks for your work!
I created a very minified test application that crashes on my phone. I hope that this could help :)
https://github.com/hahnjo/ActionBarSherlock-Test

hahnjo

@SimonVT
Collaborator
@hahnjo

Ok, sorry for that. I recreated the Test-Application and missed a few things, as you noticed.
But I think, I have now found the issue I meant in the beginning:
If you use the theme Theme.Sherlock.Light.DarkActionBar and create the view with new SearchView(this), it won't work...
Combinations that will work:
Theme.Sherlock.Light.DarkActionBar with new SearchView(getSupportActionBar().getThemedContext())
Theme.Sherlock.Light or Theme.Sherlock.Light with new SearchView(this)
I hope I have now the correct version on my github ;)
hahnjo

@SimonVT
Collaborator

Thanks for the test case.
I guess we could fix that, but you're supposed to use getSupportActionBar().getThemedContext().

@hahnjo

Yes, I'm now doing so

@ffgiraldez

what's the current status of this issue? i have the same problems on ICS devices

@SimonVT
Collaborator

The status is that there is no issue when you use SearchView like you're supposed to. Currently no plans to support wrong ways.

@jcampbell05
@SimonVT
Collaborator

Our testing has shown no issues when using the themed context, and we have received no test cases that shows otherwise.

@jcampbell05
@RobGThai

Is it possible to use themed context in XML? When I'm trying to inflate view using inflater provided in onCreateView and getting this error. I have to manually create it in code using themed context then it works.

@JakeWharton
Owner

XML inflation should be using the themed context for any widget specified as an action provider.

@JakeWharton
Owner

Er, that was supposed to end with: I'll double check tonight.

@SimonVT
Collaborator

I'm assuming he means the LayoutInflater provided in Fragment#onCreateView.. No, that doesn't use the themed context. Only views that go in the action bar should use the themed context.

@JakeWharton
Owner

Ah, I see what you're saying now (I was on mobile before). Inflation from menu XML will work because the MenuInflater uses the themed context when creating its LayoutInflater. If you are using any other provided LayoutInflater it will not work and if you are obtaining you own LayoutInflater you must manually give it the themed context from the action bar.

@SimonVT SimonVT closed this
@grossamit

I used all the possible combinations -> NO SUCCESS
crash:
01-25 15:23:27.654: E/AndroidRuntime(28317): FATAL EXCEPTION: main
01-25 15:23:27.654: E/AndroidRuntime(28317): java.lang.StackOverflowError
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.ViewGroup.addFocusables(ViewGroup.java:883)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.ViewGroup.addFocusables(ViewGroup.java:883)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.View.addFocusables(View.java:6292)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.FocusFinder.findNextInputFocus(FocusFinder.java:100)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.FocusFinder.findNextFocus(FocusFinder.java:83)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.FocusFinder.findNextFocus(FocusFinder.java:65)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.ViewGroup.focusSearch(ViewGroup.java:644)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.ViewGroup.focusSearch(ViewGroup.java:646)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.ViewGroup.focusSearch(ViewGroup.java:646)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.ViewGroup.focusSearch(ViewGroup.java:646)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.ViewGroup.focusSearch(ViewGroup.java:646)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.ViewGroup.focusSearch(ViewGroup.java:646)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.ViewGroup.focusSearch(ViewGroup.java:646)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.ViewGroup.focusSearch(ViewGroup.java:646)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.ViewGroup.focusSearch(ViewGroup.java:646)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.ViewGroup.focusSearch(ViewGroup.java:646)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.View.focusSearch(View.java:6195)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.widget.TextView.onCreateInputConnection(TextView.java:5707)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.inputmethod.InputMethodManager.startInputInner(InputMethodManager.java:1079)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.view.inputmethod.InputMethodManager.restartInput(InputMethodManager.java:1033)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.widget.TextView.setText(TextView.java:3625)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.widget.TextView.setText(TextView.java:3563)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.widget.EditText.setText(EditText.java:100)
01-25 15:23:27.654: E/AndroidRuntime(28317): at android.widget.TextView.setText(TextView.java:3538)
01-25 15:23:27.654: E/AndroidRuntime(28317): at com.actionbarsherlock.widget.SearchView.setQuery(SearchView.java:534)

@herrlado

The solutipn was for me to add a Sherlock Theme to the activoty it gets created <activity ....
android:theme="@style/Theme.Sherlock"
In this case als othe menuInflater works

@faridz

This appears to be related to style inheritance and the default styles.xml file generated by Eclipse Android ADT template for master/detail project. After adding sherlock theme to styles.xml I had something like this:

<!--
    Base application theme, dependent on API level. This theme is replaced
    by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="@style/Theme.Sherlock.Light.DarkActionBar">
    <!--
        Theme customizations available in newer API levels can go in
        res/values-vXX/styles.xml, while customizations related to
        backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="@style/AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

replacing the line:

<style name="AppTheme" parent="@style/AppBaseTheme">

with:

<style name="AppTheme" parent="@style/Theme.Sherlock.Light.DarkActionBar">

the crash goes away.

@kdehairy

@faridz, the problem is in the style.xml files in values-11/ and values-14/ folders. you sure missed changing the parent of "AppBaseTheme" to "@style/Theme.Sherlock.Light.DarkActionBar" in both.

@faridz

Thanks @kdehairy. That was it.

@smarek

If working from fragment note that this works for me:

class MyFragment extends SherlockFragment
...
new SearchView(getSherlockActivity().getSupportActionBar().getThemedContext());
@danielesegato

Sorry, not sure I understand here..

Are you saying using the SearchView widget from an XML layout is NOT supported by ActionbarSherlock?

Because I have this crash and I'm extending Theme.Sherlock.Light.DarkActionBar in my application.
I have a layout XML which include com.actionbarsherlock.widget.SearchView, when I inflate it from the SherlockFragment in onCreateView I get that error.

How am I supposed to give the actionbar sherlock themecontext to the inflater?

@JakeWharton
Owner

@mastro You can't. Inflate it programmatically.

@danielesegato

Ok thanks!

@danielesegato

Will it be supported in a future version? (just curious)

@SimonVT
Collaborator
@almozavr

Got this problem with SearchView as an actionView inside menu item for …Light.DarkActionBar theme.
Solution (fill up missing attrs):

<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
…
        <!--ActionBar (SearchView) fix-->
        <item name="textColorPrimary">@color/abs__primary_text_holo_light</item>
        <item name="textColorPrimaryInverse">@color/abs__primary_text_holo_dark</item>
        <item name="searchDropdownBackground">@drawable/abs__search_dropdown_dark</item>
        <item name="searchViewTextField">@drawable/abs__textfield_searchview_holo_dark</item>
        <item name="searchViewTextFieldRight">@drawable/abs__textfield_searchview_right_holo_dark</item>
        <item name="searchViewCloseIcon">@drawable/abs__ic_clear</item>
        <item name="searchViewSearchIcon">@drawable/abs__ic_search</item>
        <item name="searchViewGoIcon">@drawable/abs__ic_go</item>
        <item name="searchViewVoiceIcon">@drawable/abs__ic_voice_search</item>
        <item name="searchAutoCompleteTextView">@style/Widget.Sherlock.SearchAutoCompleteTextView.DarkActionBar</item>
…
</style>
…
<style name="Widget.Sherlock.SearchAutoCompleteTextView.DarkActionBar">
        <item name="android:textColor">?attr/textColorPrimaryInverse</item>
</style>
@JakeWharton
Owner

Did you use a context theme wrapper to instantiate? Because it works every time when you do.

@almozavr

It's all about menu inflation, and yes, as you said it's themed context

Inflation from menu XML will work because the MenuInflater uses the themed context when creating its LayoutInflater.

I posted this kind-a-solution 'cause yeah …Light.DarkActionBar theme + SearchView gives inflation errors (during menu inflation) due to missing attrs on v14. Also the problem seems to remain on dev branch (but didn't doublecheck it, sorry).

@SimonVT
Collaborator

If there's an issue, submit a test case. So far we've seen no evidence that it's broken in the context of the action bar.

@almozavr

Forgot to mention I use ABS via HoloEverywhere, so maybe the problem is in how HE creates context for menu inflater when on …Light.DarkActionBar
Thanks for you comments, should have tested it standalone before posting.

@HenriqueRocha

I'm also having this problem. I suppose the problem is in HoloEverywhere.
If I use parent="Holo.Theme.Light" the SearchView works perfectly, but if I use parent="Holo.Theme.Light.DarkActionBar" it doesn't work in Android 4.2 but works in 2.2.

@chrisstewart

I was having the same problem and the above comment fixed it for me: #685 (comment)

@wangqi060934

@kdehairy yes,you are right

@commonsguy

Just an FYI for anyone else running into this...

If you are crashing when trying to use a SearchView inflated from a menu resource, make sure that you are using getSupportMenuInflater(), and not new MenuInflater(this), to create your MenuInflater. You might think that there's no difference, if you are using com.actionbarsherlock.view.MenuInflater, but there is (somewhere, haven't gone looking to see exactly what). I was able to generate this crash in an app by using new MenuInflater(this) in an activity's onCreateOptionsMenu(), for an app themed as Theme.Sherlock.Light.DarkActionBar, and changing it to getSupportMenuInflater() resolved the problem.

@SimonVT
Collaborator

That's because you're not passing it ActionBar#getThemedContext.

@kapeels

If anybody else comes across this issue, #685 (comment) solved this for me.
Thanks!

I was following the instructions from here - http://developer.android.com/reference/android/app/LoaderManager.html

@mohamad-amin

Hi,
I also had the same problem.
This was my code in my fragment :

            SearchView sv = new  SearchView(getSherlockActivity());
        sv.setQueryHint("Search...");
        sv.setOnQueryTextListener(this);
        menu.add(0, search, 0, "Search").setActionView(sv)
        .setIcon(R.drawable.ic_action_search_new).setShowAsAction(
                MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.
                SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

But it gave me Force Close After I changed the theme of the activity.
The problem was with this line :


SearchView sv = new SearchView(getSherlockActivity());

I changed it to :


SearchView sv = new SearchView(getSherlockActivity().getSupportActionBar().getThemedContext());

And it's working now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.