• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Problems with displaying Text in EditText

darthevil

Lurker
Jan 28, 2012
5
0
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:
private void Home(){
        avg = (EditText) findViewById(R.id.avg);
        avg.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(3,2)});
        cavg = (EditText) findViewById(R.id.cavg);
        cavg.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(3,2)});
        std = (EditText) findViewById(R.id.stddev);
        std.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(3,2)});
        isg = (EditText) findViewById(R.id.isg);
        isg.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(3,2)});
        calculate = (Button)findViewById(R.id.calculate);
        reset = (Button)findViewById(R.id.reset);     
        calculate.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ 
            try {
                calculate();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
         }});
        reset.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ try {
            reset();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } }});
    }
                
    private void calculate() throws Exception{ 
        double CRC = 0;
        Log.d("calculate", "Before the variables");
        a=Double.parseDouble(avg.getText().toString());
        c=Double.parseDouble(cavg.getText().toString());
        s=Double.parseDouble(std.getText().toString());
        i=Double.parseDouble(isg.getText().toString());
        Log.d("calculate", "After the variables");
        CRC = 5 * (((a - c) / s) + 5 + ((i - 75) / 14));
        Log.d("calculate", "After calculation");
        
        RC.setText(Double.toString(CRC));
        
        Log.d("calculate", "displaying");
        
    }
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.
 
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.

//Here I press try to initiate a calculation which should then display to an EditText but doesn't.


01-28 14:39:36.966: D/calculate(220): Before the variables
01-28 14:39:36.974: D/calculate(220): After the variables
01-28 14:39:36.974: D/calculate(220): After calculation
01-28 14:39:36.984: W/System.err(220): java.lang.NullPointerException
01-28 14:39:36.984: W/System.err(220): at com.application.CRC.CRC.calculate(CRC.java:86)
01-28 14:39:36.995: W/System.err(220): at com.application.CRC.CRC.access$0(CRC.java:75)
01-28 14:39:36.995: W/System.err(220): at com.application.CRC.CRC$1.onClick(CRC.java:60)
01-28 14:39:36.995: W/System.err(220): at android.view.View.performClick(View.java:2364)
01-28 14:39:37.004: W/System.err(220): at android.view.View.onTouchEvent(View.java:4179)
01-28 14:39:37.004: W/System.err(220): at android.widget.TextView.onTouchEvent(TextView.java:6541)
01-28 14:39:37.004: W/System.err(220): at android.view.View.dispatchTouchEvent(View.java:3709)
01-28 14:39:37.015: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 14:39:37.015: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 14:39:37.015: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 14:39:37.024: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 14:39:37.024: W/System.err(220): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
01-28 14:39:37.024: W/System.err(220): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
01-28 14:39:37.034: W/System.err(220): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
01-28 14:39:37.034: W/System.err(220): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
01-28 14:39:37.034: W/System.err(220): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
01-28 14:39:37.044: W/System.err(220): at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 14:39:37.044: W/System.err(220): at android.os.Looper.loop(Looper.java:123)
01-28 14:39:37.044: W/System.err(220): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-28 14:39:37.044: W/System.err(220): at java.lang.reflect.Method.invokeNative(Native Method)
01-28 14:39:37.054: W/System.err(220): at java.lang.reflect.Method.invoke(Method.java:521)
01-28 14:39:37.054: W/System.err(220): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-28 14:39:37.054: W/System.err(220): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-28 14:39:37.064: W/System.err(220): at dalvik.system.NativeStart.main(Native Method)


//Over here I press a reset button and it works but these errors show up as well.


01-28 14:39:50.645: W/System.err(220): java.lang.NullPointerException
01-28 14:39:50.655: W/System.err(220): at com.application.CRC.CRC.reset(CRC.java:96)
01-28 14:39:50.655: W/System.err(220): at com.application.CRC.CRC.access$1(CRC.java:91)
01-28 14:39:50.665: W/System.err(220): at com.application.CRC.CRC$2.onClick(CRC.java:68)
01-28 14:39:50.665: W/System.err(220): at android.view.View.performClick(View.java:2364)
01-28 14:39:50.665: W/System.err(220): at android.view.View.onTouchEvent(View.java:4179)
01-28 14:39:50.675: W/System.err(220): at android.widget.TextView.onTouchEvent(TextView.java:6541)
01-28 14:39:50.675: W/System.err(220): at android.view.View.dispatchTouchEvent(View.java:3709)
01-28 14:39:50.675: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 14:39:50.685: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 14:39:50.685: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 14:39:50.685: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
01-28 14:39:50.695: W/System.err(220): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
01-28 14:39:50.695: W/System.err(220): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
01-28 14:39:50.695: W/System.err(220): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
01-28 14:39:50.705: W/System.err(220): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
01-28 14:39:50.705: W/System.err(220): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
01-28 14:39:50.705: W/System.err(220): at android.os.Handler.dispatchMessage(Handler.java:99)
01-28 14:39:50.715: W/System.err(220): at android.os.Looper.loop(Looper.java:123)
01-28 14:39:50.715: W/System.err(220): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-28 14:39:50.715: W/System.err(220): at java.lang.reflect.Method.invokeNative(Native Method)
01-28 14:39:50.715: W/System.err(220): at java.lang.reflect.Method.invoke(Method.java:521)
01-28 14:39:50.726: W/System.err(220): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-28 14:39:50.726: W/System.err(220): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-28 14:39:50.726: W/System.err(220): at dalvik.system.NativeStart.main(Native Method)
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones