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 7826969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:38:38+00:00 2026-06-02T09:38:38+00:00

I am sure this is really a simple solution that I am just not

  • 0

I am sure this is really a simple solution that I am just not seeing. However, I changed some features (which seems unrelated), but now I am getting a null pointer exception error and it just isn’t making itself obvious to where I can find it. If anyone could look at my code and help me out. I have been able to narrow it down to a key section of my code.
This code triggers an alert dialog:

    tableRowShots = (TableRow)findViewById(R.id.shots_row);
    tableRowShots.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            shotTextDialog().show();
            calculate();
      }

    });

here is the code for the shotTextDialog():

private Dialog shotTextDialog() {
    final View layout = View.inflate(this, R.layout.amount_edittext, null);

    final EditText savedText = (EditText) layout.findViewById(R.id.amountEditText);
    textViewShotsAmount = (TextView)findViewById(R.id.shots_amount);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Choose how many shots:");
    builder.setPositiveButton("Save", new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            myTextString = savedText.getText().toString().trim();
            TextView sizeText = (TextView)findViewById(R.id.shots_amount);
            sizeText.setText(myTextString);
            Toast.makeText(getApplicationContext(), "You have chosen " + myTextString + " shots for your drink", Toast.LENGTH_SHORT).show();
        }
    });
    builder.setView(layout);
    return builder.create();
 }

here is the code for calculate():

public void calculate() {
    double leftoverLiquid = 0;

    TextView shots = (TextView) this.findViewById(R.id.shots_amount);
    double shotsDouble = 0;
    if(shots != null) {
        shotsDouble = Double.valueOf(shots.getEditableText().toString());           
    }

    TextView powder = (TextView) this.findViewById(R.id.powder_amount);
    double powderDouble = 0;
    if(powder != null) {
        powderDouble = Double.valueOf(powder.getText().toString());
    }

    TextView add1 = (TextView) this.findViewById(R.id.additive_amount_1);
    double add1Double = 0;
    if(add1 != null) {
        add1Double = Double.valueOf(add1.getEditableText().toString());
    }

    TextView add2 = (TextView) this.findViewById(R.id.additive_amount_2);
    double add2Double = 0;
    if(add2 != null) {
        add2Double = Double.valueOf(add2.getEditableText().toString());
    }

    leftoverLiquid = size() - (powderDouble + shotsDouble + add1Double + add2Double);

    TextView liquid = (TextView) findViewById(R.id.liquid_amount);
    textViewLiquidAmount = liquid;
    liquid.setText(Double.toString(leftoverLiquid));

}

The NullPointerException error seems to fall somewhere near the line of code:

shotsDouble = Double.valueOf(shots.getEditableText().toString());

Can anyone see anything that I am missing?

  • 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-02T09:38:40+00:00Added an answer on June 2, 2026 at 9:38 am

    Just check the your TextView shots.getEditableText().toString() value, Either is not empty or it contains digits not other alphabets.

    And it something like,

     shotsDouble = Double.valueOf(shots.getText().toString().trim());  
    

    One more thing,

    public Editable getEditableText ()
    

    Return the text the TextView is displaying as an Editable object. If the text is not editable, null is returned.

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

Sidebar

Related Questions

I feel like there's a simple solution to this, but I'm not really sure
I'm sure that there's a really simple solution to this that will make me
I know this probably really simple but Im not sure what im doing wrong...
I'm sure this is really simple, but I can't for the life of me
I'm sure this is really simple and I'm drawing a giant blank, but how
I'm sure this is really simple, but I can't seem to get it working.
I'm sure this is a really simple thing, but I haven't worked in C++
I am sure this is something really simple, but I am going bonkers trying
This really has my stumped today. I'm sure its simple, but... Here is my
I´m not sure if this is really a programming question, but it's related to

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.