1. Download the #1 Android News App:   EarlyBird - News for Android
    Dismiss Notice

Problems with displaying Text in EditText

Last Updated:

  1. darthevil

    darthevil Member

    Hi guys,
    I'm new here, as well, very tired from coding (alot of trial and error) for the past few hours.

    I have an intro to java class under my belt and I'm having alot of trouble with Exceptions in my application. The issue is that I have multiple EditTexts for numerical entry and the data is then used in a formula. The formula is then supposed to output to another EditText. I'm just having a lot of difficulty with the formula part and outputting.
    Here's the code, any help would be much appreciated, thanks.

    Code (Text):
    1. private void Home(){
    2.         avg = (EditText) findViewById(R.id.avg);
    3.         avg.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(3,2)});
    4.         cavg = (EditText) findViewById(R.id.cavg);
    5.         cavg.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(3,2)});
    6.         std = (EditText) findViewById(R.id.stddev);
    7.         std.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(3,2)});
    8.         isg = (EditText) findViewById(R.id.isg);
    9.         isg.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(3,2)});
    10.         calculate = (Button)findViewById(R.id.calculate);
    11.         reset = (Button)findViewById(R.id.reset);    
    12.         calculate.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){
    13.             try {
    14.                 calculate();
    15.             } catch (Exception e) {
    16.                 // TODO Auto-generated catch block
    17.                 e.printStackTrace();
    18.             }
    19.          }});
    20.         reset.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ try {
    21.             reset();
    22.         } catch (Exception e) {
    23.             // TODO Auto-generated catch block
    24.             e.printStackTrace();
    25.         } }});
    26.     }
    28.     private void calculate() throws Exception{
    29.         double CRC = 0;
    30.         Log.d("calculate", "Before the variables");
    31.         a=Double.parseDouble(avg.getText().toString());
    32.         c=Double.parseDouble(cavg.getText().toString());
    33.         s=Double.parseDouble(std.getText().toString());
    34.         i=Double.parseDouble(isg.getText().toString());
    35.         Log.d("calculate", "After the variables");
    36.         CRC = 5 * (((a - c) / s) + 5 + ((i - 75) / 14));
    37.         Log.d("calculate", "After calculation");
    39.         RC.setText(Double.toString(CRC));
    41.         Log.d("calculate", "displaying");
    43.     }
    If you need the rest, I don't have a problem posting it but I am quite certain the problem is here, my variables are declared private at the beginning.

  2. jiminaus

    jiminaus Well-Known Member

    You mentioned you're having trouble with exceptions. Is an exception being thrown? If so, post the exception trace.

    If it's not an exception, please be more specific about what is or isn't actually happening verses what you expect to happen.
  3. darthevil

    darthevil Member

    Here's what shows up in logcat first when I try to perform a calculation using four doubles a,c,s,i and secondly when I press reset to return their EditTexts to null.

  4. darthevil

    darthevil Member

    For the calculation I've tried try/catch block and I've tried to throw a NullPointerException in the method
  5. darthevil

    darthevil Member

    I managed to figure out the problem. I accidentally forgot to declare the RC EditText in the code. All my errors are resolved now.

Share This Page