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

Apps Display amounts and calculate a result

Pooveshin

Newbie
Hi All

I am working on an android app and need some assistance, The app user needs to input an amount into an EditText (num) the app needs to display figures based on the user input which is set figures, after the app needs to add those figures and subtract it from the users input amount and give the answer in the last EditText (num10). I have attached my code below if anyone can assist me.

Much Appreciated.

Code:
public class CostForSeller extends AppCompatActivity {
    static EditText num;
    static EditText num1;
    static EditText num2;
    static EditText num3;
    static EditText num4;
    static EditText num5;
    static EditText num6;
    static EditText num9;
    static EditText num10;
    static EditText textmsg;
    double sum, num11, num12, num13, num14, num15, num16, num19, SellingCost, FinalCost;
    static final int READ_BLOCK_SIZE = 150;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cost_for_seller);
        num=(EditText)findViewById(R.id.num);//Selling price
        num1=(EditText)findViewById(R.id.num1); //Agent Commission
        num2=(EditText)findViewById(R.id.num2); //Bond Cancellation
        num3=(EditText)findViewById(R.id.num3); // Electrical Cert
        num4=(EditText)findViewById(R.id.num4); // Borer Inspection
        num5=(EditText)findViewById(R.id.num5); // Gas Certificate
        num6=(EditText)findViewById(R.id.num6); // Electric Fence Certificate
        num9=(EditText)findViewById(R.id.num9); // Fica Compliance
        num10=(EditText)findViewById(R.id.num10); // You will get out
    }

    /*        SellingCost = Double.parseDouble(num.getText().toString());
        num11 = Double.parseDouble(num1.getText().toString());
        num12 = Double.parseDouble(num2.getText().toString());
        num13 = Double.parseDouble(num3.getText().toString());
        num14 = Double.parseDouble(num4.getText().toString());
        num15 = Double.parseDouble(num5.getText().toString());
        num16 = Double.parseDouble(num6.getText().toString());
        num19 = Double.parseDouble(num9.getText().toString());
        sum = num11 + num12 + num13 + num14 + num15 + num16 + num19;
        FinalCost = SellingCost - sum;
        num10.setText((int) FinalCost);*/
    public void calbtn(View v) {
        // TODO Auto-generated method stub
        String numberString = num.getText().toString();
        int amt = Integer.valueOf(numberString);
        if (amt >= 1 && amt <= 100000)
        {
            num1.setText("R7000");
            num2.setText("R3500");
            num3.setText("R500");
            num4.setText("R450");
            num5.setText("R1500");
            num6.setText("R850");
            num9.setText("R450");
            SellingCost = Double.parseDouble(num.getText().toString());
            num11 = Double.parseDouble(num1.getText().toString());
            num12 = Double.parseDouble(num2.getText().toString());
            num13 = Double.parseDouble(num3.getText().toString());
            num14 = Double.parseDouble(num4.getText().toString());
            num15 = Double.parseDouble(num5.getText().toString());
            num16 = Double.parseDouble(num6.getText().toString());
            num19 = Double.parseDouble(num9.getText().toString());
            sum = num11 + num12 + num13 + num14 + num15 + num16 + num19;
            FinalCost = SellingCost - sum;
            num10.setText((int) FinalCost);
            //num10.setText("R13 150");
        }
        else if (amt >= 100001 && amt <= 150000)
        {
            num1.setText("R10 500");
            num2.setText("R2000");
            num3.setText("R500");
            num4.setText("R450");
            num5.setText("R1500");
            num6.setText("R850");
            num9.setText("R450");
            num10.setText("R16 650");
        }
 
A couple of questions:-

1. What's the problem?
2. What happens when the above code runs?
3. What code is calling method calbtn()?
 
A couple of questions:-

1. What's the problem?
2. What happens when the above code runs?
3. What code is calling method calbtn()?

Hi

The app crashes when I try to test it with the calculations, The method calbtn() is the button the user clicks after they enter the initial amount, after they click the button the set figures need to displayed but also sum them up take they users entered amount subtract it from the sum and display the answer in num10
 
If it crashes we need to see the stack trace from the Logcat, in order to diagnose the problem.
 
Hi
This is the error that comes up when I try to do calculations.

Code:
E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: www.propertyapp.co.za.propertyapp, PID: 2486
                  java.lang.IllegalStateException: Could not execute method for android:onClick
                      at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:275)
                      at android.view.View.performClick(View.java:5198)
                      at android.view.View$PerformClick.run(View.java:21147)
                      at android.os.Handler.handleCallback(Handler.java:739)
                      at android.os.Handler.dispatchMessage(Handler.java:95)
                      at android.os.Looper.loop(Looper.java:148)
                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                   Caused by: java.lang.reflect.InvocationTargetException
                      at java.lang.reflect.Method.invoke(Native Method)
                      at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270)
                      at android.view.View.performClick(View.java:5198) 
                      at android.view.View$PerformClick.run(View.java:21147) 
                      at android.os.Handler.handleCallback(Handler.java:739) 
                      at android.os.Handler.dispatchMessage(Handler.java:95) 
                      at android.os.Looper.loop(Looper.java:148) 
                      at android.app.ActivityThread.main(ActivityThread.java:5417) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
                   Caused by: android.content.res.Resources$NotFoundException: String resource ID #0xffffef66
                      at android.content.res.Resources.getText(Resources.java:312)
                      at android.support.v7.widget.ResourcesWrapper.getText(ResourcesWrapper.java:52)
                      at android.widget.TextView.setText(TextView.java:4417)
                      at www.propertyapp.co.za.propertyapp.CostForSeller.calbtn(CostForSeller.java:76)
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:270) 
                      at android.view.View.performClick(View.java:5198) 
                      at android.view.View$PerformClick.run(View.java:21147) 
                      at android.os.Handler.handleCallback(Handler.java:739) 
                      at android.os.Handler.dispatchMessage(Handler.java:95) 
                      at android.os.Looper.loop(Looper.java:148) 
                      at android.app.ActivityThread.main(ActivityThread.java:5417) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
 
The above is virtually useless because it doesn't show what line in your code threw the exception.
You've cut off the most important part of the stack trace.

It also appears to have been generated by a Button click listener, the code for which you have not shown in your code fragment.
 
Last edited by a moderator:
The above is virtually useless because it doesn't show what line in your code threw the exception.
You've cut off the most important part of the stack trace.

It also appears to have been generated by a Button click listener, the code for which you have not shown in your code fragment.
Hi

I found the problem, it was the code that displayed the answer which was incorrectly structured. It had to be like this
Code:
num10.setText(Double.toString(FinalCost));
 
Back
Top Bottom