java.lang.Integer error during form fill

Hi,

I came across this error when filling a form whereby when I set a field
to auto-fill with a calculation from values in previous fields, the form
crashes with the java.lang.integer error. This happens when I've set the
operands fields to type integer and set the result field to type decimal.

So for example when you divide 6 by 2, the result should be 3 but ODK
collect is unable to parse the result as decimal. So I fixed the problem by
surrounding the code in the integer widget and decimal widget by a try
catch.

Hope this helps someone with the problem

I think we generally consider this a form design issue. That is,
division will give you a decimal, so the bind in that node should be a
decimal. That said, glad to accept this is a patch. Can you file and
issue and attach your patch?

··· On Mon, May 21, 2012 at 3:22 AM, kymni wrote: > Hi, > > I came across this error when filling a form whereby when I set a field > to auto-fill with a calculation from values in previous fields, the form > crashes with the java.lang.integer error. This happens when I've set the > operands fields to type integer and set the result field to type decimal. > > So for example when you divide 6 by 2, the result should be 3 but ODK > collect is unable to parse the result as decimal. So I fixed the problem by > surrounding the code in the integer widget and decimal widget by a try > catch. > > Hope this helps someone with the problem

This is the section of DecimalWidget.java that I surrounded with the try
catch to get rid of the error:
try{
// only 15 characters allowed
InputFilter fa = new InputFilter[1];
fa[0] = new InputFilter.LengthFilter(15);
mAnswer.setFilters(fa);

        Double d = null;
        if (prompt.getAnswerValue() != null) {
            d = (Double) prompt.getAnswerValue().getValue();
        }

        NumberFormat nf = NumberFormat.getNumberInstance();
        nf.setMaximumFractionDigits(15);
        nf.setMaximumIntegerDigits(15);
        nf.setGroupingUsed(false);
        if (d != null) {
            Double dAnswer = (Double) 

prompt.getAnswerValue().getValue();
String dString = nf.format(dAnswer);
d = Double.parseDouble(dString.replace(',', '.'));
mAnswer.setText(d.toString());
}

        // disable if read only
        if (prompt.isReadOnly()) {
            setBackgroundDrawable(null);
            setFocusable(false);
            setClickable(false);
        }
    
    }catch(RuntimeException e){}
··· On Monday, 21 May 2012 17:08:37 UTC+3, Yaw Anokwa wrote: > > I think we generally consider this a form design issue. That is, > division will give you a decimal, so the bind in that node should be a > decimal. That said, glad to accept this is a patch. Can you file and > issue and attach your patch? > > On Mon, May 21, 2012 at 3:22 AM, kymni wrote: > > Hi, > > > > I came across this error when filling a form whereby when I set a field > > to auto-fill with a calculation from values in previous fields, the form > > crashes with the java.lang.integer error. This happens when I've set the > > operands fields to type integer and set the result field to type > decimal. > > > > So for example when you divide 6 by 2, the result should be 3 but ODK > > collect is unable to parse the result as decimal. So I fixed the problem > by > > surrounding the code in the integer widget and decimal widget by a try > > catch. > > > > Hope this helps someone with the problem >

Can you send me an example form with this issue?

Thanks,

Mitch

··· On Tue, May 22, 2012 at 1:30 AM, Charles Kimani wrote:

This is the section of DecimalWidget.java that I surrounded with the try
catch to get rid of the error:
try{
// only 15 characters allowed
InputFilter fa = new InputFilter[1];
fa[0] = new InputFilter.LengthFilter(15);
mAnswer.setFilters(fa);

        Double d = null;
        if (prompt.getAnswerValue() != null) {
            d = (Double) prompt.getAnswerValue().getValue();
        }

        NumberFormat nf = NumberFormat.getNumberInstance();
        nf.setMaximumFractionDigits(15);
        nf.setMaximumIntegerDigits(15);
        nf.setGroupingUsed(false);
        if (d != null) {
            Double dAnswer = (Double)

prompt.getAnswerValue().getValue();
String dString = nf.format(dAnswer);
d = Double.parseDouble(dString.replace(',', '.'));
mAnswer.setText(d.toString());
}

        // disable if read only
        if (prompt.isReadOnly()) {
            setBackgroundDrawable(null);
            setFocusable(false);
            setClickable(false);
        }

    }catch(RuntimeException e){}

On Monday, 21 May 2012 17:08:37 UTC+3, Yaw Anokwa wrote:

I think we generally consider this a form design issue. That is,
division will give you a decimal, so the bind in that node should be a
decimal. That said, glad to accept this is a patch. Can you file and
issue and attach your patch?

On Mon, May 21, 2012 at 3:22 AM, kymni charles@upande.com wrote:

Hi,

I came across this error when filling a form whereby when I set a field
to auto-fill with a calculation from values in previous fields, the
form
crashes with the java.lang.integer error. This happens when I've set
the
operands fields to type integer and set the result field to type
decimal.

So for example when you divide 6 by 2, the result should be 3 but ODK
collect is unable to parse the result as decimal. So I fixed the
problem by
surrounding the code in the integer widget and decimal widget by a try
catch.

Hope this helps someone with the problem

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

Attached is an example form. If you divide 12 by say 5, the form runs well.
but if you divide by any number which it's evenly divisible by, it crashes
with a java.lang.integer error. But you edit the above code by adding the
try catch, it runs well regardless of the input

example.xml (1.1 KB)

··· On Tuesday, 22 May 2012 20:08:09 UTC+3, Mitch wrote: > > Can you send me an example form with this issue? > > Thanks, > > Mitch > > On Tue, May 22, 2012 at 1:30 AM, Charles Kimani wrote: > >> This is the section of DecimalWidget.java that I surrounded with the try >> catch to get rid of the error: >> try{ >> // only 15 characters allowed >> InputFilter[] fa = new InputFilter[1]; >> fa[0] = new InputFilter.LengthFilter(15); >> mAnswer.setFilters(fa); >> >> Double d = null; >> if (prompt.getAnswerValue() != null) { >> d = (Double) prompt.getAnswerValue().getValue(); >> } >> >> NumberFormat nf = NumberFormat.getNumberInstance(); >> nf.setMaximumFractionDigits(15); >> nf.setMaximumIntegerDigits(15); >> nf.setGroupingUsed(false); >> if (d != null) { >> Double dAnswer = (Double) >> prompt.getAnswerValue().getValue(); >> String dString = nf.format(dAnswer); >> d = Double.parseDouble(dString.replace(',', '.')); >> mAnswer.setText(d.toString()); >> } >> >> // disable if read only >> if (prompt.isReadOnly()) { >> setBackgroundDrawable(null); >> setFocusable(false); >> setClickable(false); >> } >> >> }catch(RuntimeException e){} >> >> On Monday, 21 May 2012 17:08:37 UTC+3, Yaw Anokwa wrote: >>> >>> I think we generally consider this a form design issue. That is, >>> division will give you a decimal, so the bind in that node should be a >>> decimal. That said, glad to accept this is a patch. Can you file and >>> issue and attach your patch? >>> >>> On Mon, May 21, 2012 at 3:22 AM, kymni wrote: >>> > Hi, >>> > >>> > I came across this error when filling a form whereby when I set a >>> field >>> > to auto-fill with a calculation from values in previous fields, the >>> form >>> > crashes with the java.lang.integer error. This happens when I've set >>> the >>> > operands fields to type integer and set the result field to type >>> decimal. >>> > >>> > So for example when you divide 6 by 2, the result should be 3 but ODK >>> > collect is unable to parse the result as decimal. So I fixed the >>> problem by >>> > surrounding the code in the integer widget and decimal widget by a try >>> > catch. >>> > >>> > Hope this helps someone with the problem >>> >> > > > -- > Mitch Sundt > Software Engineer > University of Washington > mitchellsundt@gmail.com >

Looks like "div" generates a type "int" if they are evenly divisible
and a "decimal" if they are not. Needs a cast of at least one of the
"int"s to "decimal" before doing the "div".

··· On Tue, May 22, 2012 at 10:53 PM, Charles Kimani wrote: > Attached is an example form. If you divide 12 by say 5, the form runs well. > but if you divide by any number which it's evenly divisible by, it crashes > with a java.lang.integer error. But you edit the above code by adding the > try catch, it runs well regardless of the input > > > On Tuesday, 22 May 2012 20:08:09 UTC+3, Mitch wrote: >> >> Can you send me an example form with this issue? >> >> Thanks, >> >> Mitch >> >> On Tue, May 22, 2012 at 1:30 AM, Charles Kimani wrote: >>> >>> This is the section of DecimalWidget.java that I surrounded with the try >>> catch to get rid of the error: >>> try{ >>> // only 15 characters allowed >>> InputFilter[] fa = new InputFilter[1]; >>> fa[0] = new InputFilter.LengthFilter(15); >>> mAnswer.setFilters(fa); >>> >>> Double d = null; >>> if (prompt.getAnswerValue() != null) { >>> d = (Double) prompt.getAnswerValue().getValue(); >>> } >>> >>> NumberFormat nf = NumberFormat.getNumberInstance(); >>> nf.setMaximumFractionDigits(15); >>> nf.setMaximumIntegerDigits(15); >>> nf.setGroupingUsed(false); >>> if (d != null) { >>> Double dAnswer = (Double) >>> prompt.getAnswerValue().getValue(); >>> String dString = nf.format(dAnswer); >>> d = Double.parseDouble(dString.replace(',', '.')); >>> mAnswer.setText(d.toString()); >>> } >>> >>> // disable if read only >>> if (prompt.isReadOnly()) { >>> setBackgroundDrawable(null); >>> setFocusable(false); >>> setClickable(false); >>> } >>> >>> }catch(RuntimeException e){} >>> >>> On Monday, 21 May 2012 17:08:37 UTC+3, Yaw Anokwa wrote: >>>> >>>> I think we generally consider this a form design issue. That is, >>>> division will give you a decimal, so the bind in that node should be a >>>> decimal. That said, glad to accept this is a patch. Can you file and >>>> issue and attach your patch? >>>> >>>> On Mon, May 21, 2012 at 3:22 AM, kymni wrote: >>>> > Hi, >>>> > >>>> > I came across this error when filling a form whereby when I set a >>>> > field >>>> > to auto-fill with a calculation from values in previous fields, the >>>> > form >>>> > crashes with the java.lang.integer error. This happens when I've set >>>> > the >>>> > operands fields to type integer and set the result field to type >>>> > decimal. >>>> > >>>> > So for example when you divide 6 by 2, the result should be 3 but ODK >>>> > collect is unable to parse the result as decimal. So I fixed the >>>> > problem by >>>> > surrounding the code in the integer widget and decimal widget by a try >>>> > catch. >>>> > >>>> > Hope this helps someone with the problem >> >> >> >> >> -- >> Mitch Sundt >> Software Engineer >> University of Washington >> mitchellsundt@gmail.com

I just confirmed that this was fixed in the source 3 weeks ago but not
built and pushed to Google Play.

We'll get a new build out soon -- Carl and Yaw have been distracted with
dissertation deadlines.

Mitch

··· On Tue, May 22, 2012 at 11:30 PM, Gaetano Borriello < gaetano@cs.washington.edu> wrote:

Looks like "div" generates a type "int" if they are evenly divisible
and a "decimal" if they are not. Needs a cast of at least one of the
"int"s to "decimal" before doing the "div".

On Tue, May 22, 2012 at 10:53 PM, Charles Kimani kymkimani@gmail.com wrote:

Attached is an example form. If you divide 12 by say 5, the form runs
well.
but if you divide by any number which it's evenly divisible by, it
crashes
with a java.lang.integer error. But you edit the above code by adding the
try catch, it runs well regardless of the input

On Tuesday, 22 May 2012 20:08:09 UTC+3, Mitch wrote:

Can you send me an example form with this issue?

Thanks,

Mitch

On Tue, May 22, 2012 at 1:30 AM, Charles Kimani kymkimani@gmail.com wrote:

This is the section of DecimalWidget.java that I surrounded with the
try
catch to get rid of the error:
try{
// only 15 characters allowed
InputFilter fa = new InputFilter[1];
fa[0] = new InputFilter.LengthFilter(15);
mAnswer.setFilters(fa);

        Double d = null;
        if (prompt.getAnswerValue() != null) {
            d = (Double) prompt.getAnswerValue().getValue();
        }

        NumberFormat nf = NumberFormat.getNumberInstance();
        nf.setMaximumFractionDigits(15);
        nf.setMaximumIntegerDigits(15);
        nf.setGroupingUsed(false);
        if (d != null) {
            Double dAnswer = (Double)

prompt.getAnswerValue().getValue();
String dString = nf.format(dAnswer);
d = Double.parseDouble(dString.replace(',', '.'));
mAnswer.setText(d.toString());
}

        // disable if read only
        if (prompt.isReadOnly()) {
            setBackgroundDrawable(null);
            setFocusable(false);
            setClickable(false);
        }

    }catch(RuntimeException e){}

On Monday, 21 May 2012 17:08:37 UTC+3, Yaw Anokwa wrote:

I think we generally consider this a form design issue. That is,
division will give you a decimal, so the bind in that node should be a
decimal. That said, glad to accept this is a patch. Can you file and
issue and attach your patch?

On Mon, May 21, 2012 at 3:22 AM, kymni charles@upande.com wrote:

Hi,

I came across this error when filling a form whereby when I set a
field
to auto-fill with a calculation from values in previous fields, the
form
crashes with the java.lang.integer error. This happens when I've set
the
operands fields to type integer and set the result field to type
decimal.

So for example when you divide 6 by 2, the result should be 3 but
ODK
collect is unable to parse the result as decimal. So I fixed the
problem by
surrounding the code in the integer widget and decimal widget by a
try
catch.

Hope this helps someone with the problem

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com

--
Mitch Sundt
Software Engineer
University of Washington
mitchellsundt@gmail.com