Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App crashing when Selecting/Scrolling items on Spinner. (LG Mobile) (java.lang.IllegalStateException: Iteration already started)

I made on app in which User has to select an integer from the Spinner. I am populating the Spinner using Adapter. The code is like this.

Integer[] intArray = new Integer[500];
        for (int i = 0; i < 500; i++)
            intArray[i] = i + 1;

        ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this, android.R.layout.simple_spinner_dropdown_item, intArray);
        spinner.setAdapter(adapter);

The app is written for API-21. It worked perfectly on Samsung-mobile but when I tried to run it on LG-Mobile, the app is crashing whenever i am scrolling the items in the spinner. The Error is something new as i didn't find similar error. Error goes like this

process: com.example.temp.project, PID: 12142
    java.lang.IllegalStateException: Iteration already started
            at android.view.ViewTreeObserver$CopyOnWriteArray.start(ViewTreeObserver.java:987)
            at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:811)
            at android.widget.PopupWindow.update(PopupWindow.java:1524)
            at android.widget.PopupWindow.update(PopupWindow.java:1654)
            at android.widget.PopupWindow.update(PopupWindow.java:1607)
            at android.widget.ListPopupWindow.show(ListPopupWindow.java:612)
            at android.widget.Spinner$DropdownPopup.access$701(Spinner.java:1069)
            at android.widget.Spinner$DropdownPopup$2.onGlobalLayout(Spinner.java:1178)
            at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:815)
            at android.widget.PopupWindow.update(PopupWindow.java:1524)
            at android.widget.PopupWindow.update(PopupWindow.java:1654)
            at android.widget.PopupWindow.update(PopupWindow.java:1607)
            at android.widget.ListPopupWindow.show(ListPopupWindow.java:612)
            at android.widget.ListPopupWindow$ResizePopupRunnable.run(ListPopupWindow.java:1759)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5299)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)

Any hint that how can i solve this issue.

like image 446
Saad Saadi Avatar asked Nov 23 '15 01:11

Saad Saadi


1 Answers

Here is my solution. It might not be a perfect solution but worked for me. In my original XML file, i was using GraphView above the spinner's Layout, like this

<LinearLayout

        android:id="@+id/main_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="1"
        android:layout_alignParentTop="true">

        <com.jjoe64.graphview.GraphView
            android:id="@+id/graph_view"
            android:layout_width="match_parent"
            android:layout_height="230dp"
            android:orientation="vertical"
            />

        <LinearLayout
            android:layout_marginTop="10dp"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="80dp">

            <Spinner
                android:layout_marginLeft="10dp"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:id="@+id/SSspinner"
                android:layout_weight="1" />

            <Spinner
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:id="@+id/Avgspinner"
                android:layout_weight="1" />

        </LinearLayout>


</LinearLayout>

The problem was kind of new as i didn't find any problem like this on net. After reading from different sources, i realized it is layout issue. This is what I did then

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:orientation="horizontal">

            <Spinner
                android:id="@+id/SSspinner"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:layout_marginLeft="10dp"
                android:layout_weight="1" />

            <Spinner
                android:id="@+id/Avgspinner"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_weight="1" />

        </LinearLayout>

    <LinearLayout

        android:layout_marginTop="80dp"
        android:id="@+id/main_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:orientation="vertical"
        android:weightSum="1">


 <com.jjoe64.graphview.GraphView
                android:id="@+id/graph_view"
                android:layout_width="match_parent"
                android:layout_height="230dp"
                android:orientation="vertical"
                />

</LinearLayout>
like image 108
Saad Saadi Avatar answered Oct 17 '22 14:10

Saad Saadi