Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old January 28th, 2012, 12:40 AM   #1 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jan 2012
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems with displaying Text in EditText

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.

Advertisements
darthevil is offline  
Reply With Quote
sponsored links
Old January 28th, 2012, 03:00 AM   #2 (permalink)
Member
 
Join Date: Oct 2011
Location: Sydney, Australia
Posts: 191
 
Device(s): Galaxy Nexus GSM
Carrier: Not Provided

Thanks: 2
Thanked 37 Times in 33 Posts
Default

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.
jiminaus is offline  
Last edited by jiminaus; January 28th, 2012 at 03:02 AM.
Reply With Quote
Old January 28th, 2012, 01:44 PM   #3 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jan 2012
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Quote:
//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:370 9)
01-28 14:39:37.015: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGrou p.java:884)
01-28 14:39:37.015: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGrou p.java:884)
01-28 14:39:37.015: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGrou p.java:884)
01-28 14:39:37.024: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGrou p.java:884)
01-28 14:39:37.024: W/System.err(220): at com.android.internal.policy.impl.PhoneWindow$Decor View.superDispatchTouchEvent(PhoneWindow.java:1659 )
01-28 14:39:37.024: W/System.err(220): at com.android.internal.policy.impl.PhoneWindow.super DispatchTouchEvent(PhoneWindow.java:1107)
01-28 14:39:37.034: W/System.err(220): at android.app.Activity.dispatchTouchEvent(Activity.j ava:2061)
01-28 14:39:37.034: W/System.err(220): at com.android.internal.policy.impl.PhoneWindow$Decor View.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.jav a: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$MethodAndArgsCa ller.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:370 9)
01-28 14:39:50.675: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGrou p.java:884)
01-28 14:39:50.685: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGrou p.java:884)
01-28 14:39:50.685: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGrou p.java:884)
01-28 14:39:50.685: W/System.err(220): at android.view.ViewGroup.dispatchTouchEvent(ViewGrou p.java:884)
01-28 14:39:50.695: W/System.err(220): at com.android.internal.policy.impl.PhoneWindow$Decor View.superDispatchTouchEvent(PhoneWindow.java:1659 )
01-28 14:39:50.695: W/System.err(220): at com.android.internal.policy.impl.PhoneWindow.super DispatchTouchEvent(PhoneWindow.java:1107)
01-28 14:39:50.695: W/System.err(220): at android.app.Activity.dispatchTouchEvent(Activity.j ava:2061)
01-28 14:39:50.705: W/System.err(220): at com.android.internal.policy.impl.PhoneWindow$Decor View.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.jav a: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$MethodAndArgsCa ller.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)
darthevil is offline  
Reply With Quote
Old January 28th, 2012, 01:46 PM   #4 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jan 2012
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

For the calculation I've tried try/catch block and I've tried to throw a NullPointerException in the method
darthevil is offline  
Reply With Quote
Old January 28th, 2012, 02:35 PM   #5 (permalink)
New Member
Thread Author (OP)
 
Join Date: Jan 2012
Posts: 5
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

I managed to figure out the problem. I accidentally forgot to declare the RC EditText in the code. All my errors are resolved now.
darthevil is offline  
Reply With Quote
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 01:26 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.