arimorty / floatingsearchview

A search view that implements a floating search bar also known as persistent search
https://github.com/arimorty/floatingsearchview/blob/master/README.md
Apache License 2.0
3.54k stars 667 forks source link

Array index out of bounds exception #58

Closed TheRishka closed 8 years ago

TheRishka commented 8 years ago

Hi! I've implemented your library in my proj and when I click somewhere outside of search box, it crashes with ArrayIndexOutOfBoundsException in MenuView. Here is the stacktrace:

java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
                   at android.animation.AnimatorSet.playTogether(AnimatorSet.java:142)
                   at com.arlib.floatingsearchview.util.view.MenuView.showIfRoomItems(MenuView.java:506)
                   at com.arlib.floatingsearchview.FloatingSearchView.setSearchFocusedInternal(FloatingSearchView.java:1361)
                   at com.arlib.floatingsearchview.FloatingSearchView.access$1500(FloatingSearchView.java:87)
                   at com.arlib.floatingsearchview.FloatingSearchView$23.onTouch(FloatingSearchView.java:1657)
                   at android.view.View.dispatchTouchEvent(View.java:8382)
arimorty commented 8 years ago

Hi @TheRishka ,

It would be useful if you can provide a step-by-step instructions for reproducing the problem

TheRishka commented 8 years ago

What kind of info do you need? Here is my xml:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/map_fragment"
        android:name="MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"/>

    <com.arlib.floatingsearchview.FloatingSearchView
        android:id="@+id/points_map_search_bar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:floatingSearch_searchBarMarginLeft="@dimen/margin_medium"
        app:floatingSearch_searchBarMarginTop="@dimen/margin_medium"
        app:floatingSearch_searchBarMarginRight="@dimen/margin_medium"
        app:floatingSearch_searchHint="@string/search_view_hint_text"
        app:floatingSearch_showSearchKey="false"
        app:floatingSearch_leftActionMode="noLeftAction"
        app:floatingSearch_menu="@menu/menu_search"/>

</FrameLayout>

Some java code relative to SearchView:

        if(mSearchView != null) {
            mSearchView.setOnQueryChangeListener(searchInputListener);
            mSearchView.setOnHomeActionClickListener(() -> {
                mSearchView.clearSearchFocus();
            });
        }

As it comes from code, tapping on homeAction should remove focus from SearchView and collapse it. But...it crashes as well as it does if you tap outside of it. It appears to be a bug of animation. MinSDK - 21, Target - 23

TheRishka commented 8 years ago

Ok, I got it now. It crashes if there are empty menu file. What should I do to prevent crashing but leave no items in menu? I don't need any additional menu items, just blank search bar.

arimorty commented 8 years ago
  1. Is minifyEnabled set to true in your project?
  2. What version of the library are you using?

If you are not using the latest version (2.0.1), please update and see if you still get the crash.

TheRishka commented 8 years ago
  1. Nope, minify is disabled in my project in debug version.
  2. Ye, I've updated to 2.0.1 and still got the same issue. Apparently, I can't have a blank search bar.There must be at least one item in menu or it crashes
arimorty commented 8 years ago

There must be something else in your code that I am missing, I will investigate this bug in the next couple of days. Any additional details will be appreciated as I am unable to reproduce the issue.

In any case, OnHomeActionClickListener is only called when the searchBar is not focused, so your call mSearchView.clearSearchFocus(); will only get called when the search is already not focused. When search is focused, a click to back arrow will be handled by the searchView itself.

acarlsen commented 8 years ago

I have the same issue. It happens if I dont supply a icon resource to the menu item, fx. if I only want to display text. If I supply a drawable as icon the error doesn't happen.

drjunior commented 8 years ago

I also have this problem http://crashes.to/s/820fbc8afe8 I've been checking anf the return of the method getAdapterPosition() is not being tested and it can return -1 RecyclerView#NO_POSITION if item has been removed from the adapter and seems to be the case. Could you simply add that condition? Thanks.

drjunior commented 8 years ago

Actually the bug that I was experiencing is the same (ArrayIndexOutOfBoundsException) but has another stacktrace which means that is another problem. I've just created a PR to fix the problem that I've been experiencing. https://github.com/arimorty/floatingsearchview/pull/85

Thanks.

arimorty commented 8 years ago

@acarlsen thanks, I am trying to resolve this bug and that's what the problem is.