Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8382507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:56:36+00:00 2026-06-09T16:56:36+00:00

Can someone check my code? I am having my calculation for the score using

  • 0

Can someone check my code? I am having my calculation for the score using TextView and EditText, i also declared Integers for the variables, but when i run my code, it gives me error when parsing integer. Thanks in advance. Also check my Log cat for more info. Here’s my code:

 initControls();
      }
      private void initControls()
      {
          amount1=(EditText)findViewById(R.id.amount1);
          amount2=(EditText)findViewById(R.id.amount2);
          amount3=(EditText)findViewById(R.id.amount3);
          result=(TextView)findViewById(R.id.result);
          calculate=(Button)findViewById(R.id.finish);
          calculate.setOnClickListener(new Button.OnClickListener()
          {public void onClick
          (View  v) { calculate();}});
      }
      private void calculate()
      {

          if(amount1.getText().toString().equals(null))
          {
          x=0;
          }
          else
              amount1.getText().toString();
              x=Integer.parseInt(amount1.getText().toString());

      if(amount2.getText().toString().equals(null)) {
          y=0; 
      }
      else
          amount2.getText().toString();
          y=Integer.parseInt(amount2.getText().toString());

     if(amount3.getText().toString().equals(null)) {
          v=0;
      }
     else
    amount3.getText().toString();
      v=Integer.parseInt(amount3.getText().toString());
      {
          z=x+y+v;
          result.setText(Integer.toString(z));
      }

Here’s my Log cat:

08-16 16:15:51.794: W/dalvikvm(224): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
08-16 16:15:51.794: E/AndroidRuntime(224): Uncaught handler: thread main exiting due to uncaught exception
08-16 16:15:51.824: E/AndroidRuntime(224): java.lang.NumberFormatException: unable to parse '' as integer
08-16 16:15:51.824: E/AndroidRuntime(224):  at java.lang.Integer.parseInt(Integer.java:353)
08-16 16:15:51.824: E/AndroidRuntime(224):  at java.lang.Integer.parseInt(Integer.java:323)
08-16 16:15:51.824: E/AndroidRuntime(224):  at drj.thesis.tridi.Maingame.calculate(Maingame.java:70)
08-16 16:15:51.824: E/AndroidRuntime(224):  at drj.thesis.tridi.Maingame.access$0(Maingame.java:54)
08-16 16:15:51.824: E/AndroidRuntime(224):  at drj.thesis.tridi.Maingame$1.onClick(Maingame.java:52)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.view.View.performClick(View.java:2364)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.view.View.onTouchEvent(View.java:4179)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.widget.TextView.onTouchEvent(TextView.java:6541)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.view.View.dispatchTouchEvent(View.java:3709)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-16 16:15:51.824: E/AndroidRuntime(224):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
08-16 16:15:51.824: E/AndroidRuntime(224):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
08-16 16:15:51.824: E/AndroidRuntime(224):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.os.Looper.loop(Looper.java:123)
08-16 16:15:51.824: E/AndroidRuntime(224):  at android.app.ActivityThread.main(ActivityThread.java:4363)
08-16 16:15:51.824: E/AndroidRuntime(224):  at java.lang.reflect.Method.invokeNative(Native Method)
08-16 16:15:51.824: E/AndroidRuntime(224):  at java.lang.reflect.Method.invoke(Method.java:521)
08-16 16:15:51.824: E/AndroidRuntime(224):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-16 16:15:51.824: E/AndroidRuntime(224):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-16 16:15:51.824: E/AndroidRuntime(224):  at dalvik.system.NativeStart.main(Native Method)
08-16 16:15:51.857: I/dalvikvm(224): threadid=7: reacting to signal 3
08-16 16:15:51.864: E/dalvikvm(224): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:56:38+00:00Added an answer on June 9, 2026 at 4:56 pm

    The problem is fairly clear:

    java.lang.NumberFormatException: unable to parse '' as integer
    

    You’re trying to parse an empty string. You need to work out why you’re trying to parse an empty string.

    I suspect this is a large part of it:

     if(amount1.getText().toString().equals(null))
     {
        x=0;
     }
     else
        amount1.getText().toString();
        x=Integer.parseInt(amount1.getText().toString());
    

    You should have braces around your else block so that both statements are in it:

     if(amount1.getText().toString().equals(null))
     {
        x=0;
     }
     else
     {
        amount1.getText().toString();
        x=Integer.parseInt(amount1.getText().toString());
     }
    

    … although the first statement in the else block looks pointless to me.

    I’d actually expect amount1.getText() to already return a string though, making the toString() call unnecessary (maybe not; this could be an Android facet I don’t know about) but I’d never expect the result to be equal to null. Perhaps you meant to compare with “” like this:

     if(amount1.getText().toString().equals(""))
     {
        x=0;
     }
     else
     {
        // Removed pointless call to amount1.getText().toString()
        x=Integer.parseInt(amount1.getText().toString());
     }
    

    (You can use amount1.getText().toString().getLength() == 0 to check for an empty string too. It’s a matter of preference which you pick.)

    You’ve got the same problem just below this as well, suggesting you should probably extract a method to perform this conditional parsing.

    Additionally, you should really fix your indentation. Indenting code properly makes a huge difference to code readability.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would try it myself, but I can't. Could someone check for me? I
Can someone thoroughly explain the last line of the following code: def myMethod(self): #
I would like to check an attribute using C# and SimpleDB without having to
Can someone tell me why this unit test that checks for exceptions fails? Obviously
Can someone please tell me what this means: 07-04 09:54:38.048: I/DetailActivity(15496): Title that is
Can someone please explain why ?___SID=U is appearing in some Magento URLs on my
Can someone please explain how Read/Show works.. I cannot find any tutorials on it.
Can someone please provide an example of how to store, and read xml data
Can someone tell me how to modify this regex to allow periods in a
can someone tell me what seems to be the issue with this <?php $increment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.