material-singleinputform
material-singleinputform copied to clipboard
java.lang.IndexOutOfBoundsException: Index: 12, Size: 12
at java.util.ArrayList.get(ArrayList.java:411) at com.heinrichreimersoftware.singleinputform.SingleInputFormActivity.getStep(SingleInputFormActivity.java:200) at com.heinrichreimersoftware.singleinputform.SingleInputFormActivity.getCurrentStep(SingleInputFormActivity.java:196) at com.heinrichreimersoftware.singleinputform.SingleInputFormActivity.nextStep(SingleInputFormActivity.java:408) at com.heinrichreimersoftware.singleinputform.SingleInputFormActivity$2.onClick(SingleInputFormActivity.java:100) at android.view.View.performClick(View.java:5637) at android.view.View$PerformClick.run(View.java:22433) at android.os.Handler.handleCallback(Handler.java:751) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6195) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
this keeps happening whenever you click the finish button it throws indexOutOfBoundException:index: yourStepsSize, size: yourStepsSize (if you have 6 steps it tries to access the 6th element of array of size 6 which doesn't exist)
In my SingleInputFormActivity subclass I have added this override:
@Override
public void onSaveInstanceState(Bundle outState) {
// propagating this call to super when the current stepIndex has been incremented to
// steps.size() by the most recent call to nextStep() will throw an IndexOutOfBoundsException
// while trying to save the state, it is harmless to simply skip it entirely since
// everything has already been saved into the bundle
try {
getCurrentStep();
} catch (IndexOutOfBoundsException e) {
return;
}
super.onSaveInstanceState(outState);
}
It's perfectly harmless to do this check. If you need to save other state then make sure to do it at the start of the method.
(Over here I get the same error while Android attempts to save the activity instance state, you might want to consider doing a similar check in you onClick handler)
Interestingly this doesn't crash my physical device, but emulators and other people I have asked to test my app suffer crashes.
I need to implement the fix that you mention, but I need to work out how to include this library in a way that I can edit. I still don't fully understand what I am doing!
Do you have any idea how to reproduce this bug? I can't reproduce it in any way. I'm working on a pull request, but I can't find out why this bug happens.
Thanks in advance.