IndexOutOfBounds on Spinner?

I have a problem with interpreting the stack trace. Peoblem is that there is no class from my package, so it's hard for me to find out what is going on. When I laid off the trace, I think it is an adapter and a spinner, but on this page I have 6 spinners, I debug them all and did not find anything strange (for example, selectedItemPosition or something else) ..

Maybe someone had a similar problem? There is a trace. If you need a code, tell me

Uncaught handler: thread main exiting due to uncaught exception java.lang.IndexOutOfBoundsException at java.util.Arrays$ArrayList.get(Arrays.java:72) at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:298) at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:351) at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323) at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:198) at android.view.View.measure(View.java:7987) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888) at android.widget.LinearLayout.measureVertical(LinearLayout.java:350) at android.widget.LinearLayout.onMeasure(LinearLayout.java:278) at android.view.View.measure(View.java:7987) at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:893) at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) at android.widget.ScrollView.onMeasure(ScrollView.java:276) at android.view.View.measure(View.java:7987) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:888) at android.widget.LinearLayout.measureVertical(LinearLayout.java:350) at android.widget.LinearLayout.onMeasure(LinearLayout.java:278) at android.view.View.measure(View.java:7987) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023) at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) at android.view.View.measure(View.java:7987) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3023) at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) at android.view.View.measure(View.java:7987) at android.view.ViewRoot.performTraversals(ViewRoot.java:763) at android.view.ViewRoot.handleMessage(ViewRoot.java:1633) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4363) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:635) at dalvik.system.NativeStart.main(Native Method) 

I do not know what to do.

+6
source share
4 answers

See if you have the setSelection () function for any of the spinners that may have an index that is larger than the size of the adapter. for example, if your counter has two elements, and if you call setSelection (2), this will throw an IndexOutOfBoundsException.

+15
source

To find what spinner is, the problem is:

  • Back up your page
  • Remove 5 from 6 clips
  • Check page
  • Repeat to save only 1 counter at a time until you have checked each counter on your page.

What would i do. Hope this helps.

0
source

In addition to @FrancescoR's comment, this code can help you avoid code failure during the attempt and track down a bad call. I had to answer this question because adding code to the comments was rather unpleasant.

 private void spinnerSetSelectionChecked(Spinner spin, int index) { spinnerSetSelectionChecked(spin, index, true); } private void spinnerSetSelectionChecked(Spinner spin, int index, boolean animate) { final int count = spin.getAdapter().getCount(); if( (count > 0) && (index < count) ) { spin.setSelection(index, animate); } else { // do nothing } } 
0
source

Inspect the log carefully, find another stack trace above or below the one you posted. I have happened to me a couple of times. Every time I think that my code is not mentioned in the stack trace, I look a second time and find it.

-1
source

Source: https://habr.com/ru/post/886972/


All Articles