Calculations using Android
<p>Really struggling to make this code work. Basically I've got a list of users inputs which is my EditTexts and using them I want to calculate the total which will be printed where TextView TotalNum is. </p>

<p>I'm teaching myself how to develop in android but I have some knowledge of Java so I would appreciate it if someone could just point out what I'm doing wrong.</p>

<p>Logcat stated there was something wrong with line 70 of this file which is </p>

<p><code>TotalNum.setText("£" + exTotal);</code></p>

<p>I've tried taking out the exTotal double figure which I thought may have caused the error however it still says 'Unfortunately <em>app name</em> has stopped working' when I press the calculate button after entering all the numbers for each EditText.</p>

<p>Any advice of how I could get my code to work would be great. It'd also be great if you could leave me some examples of similar calculations.</p>

<pre><code>public class Expense extends Activity
{
    double exTotal, exRent, exElect, exHeat, exNet, exMobile, exOther;
    TextView Total, TotalNum, Rent, Elect, Heat, Net, Mobile, Other;
    EditText eRent, eElect, eHeat, eNet, eMobile, eOther;
    String eRentS, eElectS, eHeatS, eNetS, eMobileS, eOtherS;
    Button cal;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.expense);

        Rent = (TextView) findViewById(R.id.tvRent);
        Elect = (TextView) findViewById(R.id.tvElectricity);
        Heat = (TextView) findViewById(R.id.tvHeating);
        Net = (TextView) findViewById(R.id.tvInternet);
        Mobile = (TextView) findViewById(R.id.tvMobile);
        Other = (TextView) findViewById(R.id.tvOther);
        Total = (TextView) findViewById(R.id.tvTotalExpense);
        TotalNum = (TextView) findViewById(R.id.tvExpenseNum);

        eRent = (EditText) findViewById(R.id.etRent);
        eElect = (EditText) findViewById(R.id.etElectricity);
        eHeat = (EditText) findViewById(R.id.etHeating);
        eNet = (EditText) findViewById(R.id.etInternet);
        eMobile = (EditText) findViewById(R.id.etMobile);
        eOther = (EditText) findViewById(R.id.etOther);

        cal = (Button) findViewById(R.id.bCal);






        cal.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View v) 
            {
                // TODO Auto-generated method stub              
                eRentS = eRent.getText().toString();
                eElectS = eElect.getText().toString();
                eHeatS = eHeat.getText().toString();
                eNetS = eNet.getText().toString();
                eMobileS = eMobile.getText().toString();
                eOtherS = eOther.getText().toString();

                exRent = Double.parseDouble(eRentS);
                exElect = Double.parseDouble(eElectS);
                exHeat = Double.parseDouble(eHeatS);
                exNet = Double.parseDouble(eNetS);
                exMobile = Double.parseDouble(eMobileS);
                exOther = Double.parseDouble(eOtherS);

                exTotal = exRent + exElect + exHeat + exNet + exMobile + exOther;
                TotalNum.setText("£" + exTotal);
            }

        });


    }


}
</code></pre>

<p>This is the logcat</p>

<pre><code>05-30 11:45:44.694: E/AndroidRuntime(775): FATAL EXCEPTION: main
05-30 11:45:44.694: E/AndroidRuntime(775): java.lang.NullPointerException
05-30 11:45:44.694: E/AndroidRuntime(775):  at com.studentbudget.Expense$1.onClick(Expense.java:70)
05-30 11:45:44.694: E/AndroidRuntime(775):  at android.view.View.performClick(View.java:4204)
05-30 11:45:44.694: E/AndroidRuntime(775):  at android.view.View$PerformClick.run(View.java:17355)
05-30 11:45:44.694: E/AndroidRuntime(775):  at android.os.Handler.handleCallback(Handler.java:725)
05-30 11:45:44.694: E/AndroidRuntime(775):  at android.os.Handler.dispatchMessage(Handler.java:92)
05-30 11:45:44.694: E/AndroidRuntime(775):  at android.os.Looper.loop(Looper.java:137)
05-30 11:45:44.694: E/AndroidRuntime(775):  at android.app.ActivityThread.main(ActivityThread.java:5041)
05-30 11:45:44.694: E/AndroidRuntime(775):  at java.lang.reflect.Method.invokeNative(Native Method)
05-30 11:45:44.694: E/AndroidRuntime(775):  at java.lang.reflect.Method.invoke(Method.java:511)
05-30 11:45:44.694: E/AndroidRuntime(775):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-30 11:45:44.694: E/AndroidRuntime(775):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-30 11:45:44.694: E/AndroidRuntime(775):  at dalvik.system.NativeStart.main(Native Method)
</code></pre>
