jr:count in two nested groups

Issue #59 open
aurdipas
created an issue

What steps will reproduce the problem? 1. create a form with 2 nested group one inside the other. 2. First group is repeated n>1 times where n is a value given to a previous question 3. now group 2 should be repeated p times where p is a value given to a question in group 1.

What is the expected output? What do you see instead?

the group 2 repeated p times. But the application crashes. If as p I assign a value coming from a question outside group 1 it works

<input ref="/data/NumberOfHouses"> <label ref="jr:itext('/data/NumberOfHouses:label')"/> <hint ref="jr:itext('/data/NumberOfHouses:hint')"/> </input> <group> <label ref="jr:itext('/data/House:label')"/> <repeat nodeset="/data/House" jr:count="/data/NumberOfHouses"> <input ref="/data/House/numberOfPeopleInHouse"> <label ref="jr:itext('/data/House/numberOfPeopleInHouse:label')"/> <hint ref="jr:itext('/data/House/numberOfPeopleInHouse:hint')"/> </input> <group> <label ref="jr:itext('/data/House/individuals:label')"/> <repeat nodeset="/data/House/individuals" jr:count="/data/House/numberOfPeopleInHouse"> <input ref="/data/House/individuals/permanentId"> <label ref="jr:itext('/data/House/individuals/permanentId:label')"/> <hint ref="jr:itext('/data/House/individuals/permanentId:hint')"/> </input> </repeat> </group> </repeat> </group>

Comments (6)

  1. aurdipas reporter

    03-06 09:48:03.365: E/AndroidRuntime(419): FATAL EXCEPTION: main 03-06 09:48:03.365: E/AndroidRuntime(419): java.lang.NullPointerException 03-06 09:48:03.365: E/AndroidRuntime(419): at org.javarosa.core.model.FormDef.canCreateRepeat(FormDef.java:343) 03-06 09:48:03.365: E/AndroidRuntime(419): at org.javarosa.form.api.FormEntryModel.isIndexRelevant(FormEntryModel.java:387) 03-06 09:48:03.365: E/AndroidRuntime(419): at org.javarosa.form.api.FormEntryController.stepEvent(FormEntryController.java:198) 03-06 09:48:03.365: E/AndroidRuntime(419): at org.javarosa.form.api.FormEntryController.stepToNextEvent(FormEntryController.java:169) 03-06 09:48:03.365: E/AndroidRuntime(419): at org.odk.collect.android.logic.FormController.stepToNextEvent(FormController.java:287) 03-06 09:48:03.365: E/AndroidRuntime(419): at org.odk.collect.android.activities.FormEntryActivity.showNextView(FormEntryActivity.java:836) 03-06 09:48:03.365: E/AndroidRuntime(419): at org.odk.collect.android.activities.FormEntryActivity.onFling(FormEntryActivity.java:1756) 03-06 09:48:03.365: E/AndroidRuntime(419): at android.view.GestureDetector.onTouchEvent(GestureDetector.java:568) 03-06 09:48:03.365: E/AndroidRuntime(419): at org.odk.collect.android.activities.FormEntryActivity.dispatchTouchEvent(FormEntryActivity.java:811) 03-06 09:48:03.365: E/AndroidRuntime(419): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675) 03-06 09:48:03.365: E/AndroidRuntime(419): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194) 03-06 09:48:03.365: E/AndroidRuntime(419): at android.view.ViewRoot.handleMessage(ViewRoot.java:1878) 03-06 09:48:03.365: E/AndroidRuntime(419): at android.os.Handler.dispatchMessage(Handler.java:99) 03-06 09:48:03.365: E/AndroidRuntime(419): at android.os.Looper.loop(Looper.java:123) 03-06 09:48:03.365: E/AndroidRuntime(419): at android.app.ActivityThread.main(ActivityThread.java:3647) 03-06 09:48:03.365: E/AndroidRuntime(419): at java.lang.reflect.Method.invokeNative(Native Method) 03-06 09:48:03.365: E/AndroidRuntime(419): at java.lang.reflect.Method.invoke(Method.java:507) 03-06 09:48:03.365: E/AndroidRuntime(419): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 03-06 09:48:03.365: E/AndroidRuntime(419): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 03-06 09:48:03.365: E/AndroidRuntime(419): at dalvik.system.NativeStart.main(Native Method)

  2. aurdipas reporter

    just select as number of houses 2. All ok for the first house, but on the second house when it starts the nested group for the individuals it crashes. (also tried the relative path: jr:count="./numberOfPeopleInHouse")

  3. Mitch Sundt

    Lu Gram has proposed the attached patch (jr-count-contextualize.patch) that first contextualizes the tree references before accessing their values, so that they are interpreted specific to the particular repeat in which they are nested. The changes are to FormDef:canCreateRepeat() and FormEntryModel:createModelIfNecessary(). Note that the patch is for a non-mainline branch of javarosa, so apply it with interpretation.

  4. Log in to comment