title: Using variable from onCreate
body: <p>I am new to android programming but there is something small that i can't seem to find online.
  My problem is i want to use a variable from the onCreate method in another method.
  Im sure this is online somewhere but whatever i have searched i couldnt find a soultion. Maybe i am phrasing this all wrong....
  I want to re-use the doubles in the onCreate to perform an IF statement to see if the answer is correct. App crashes at the moment..</p>
  
  <p>Here is my code:</p>
  
  <pre><code> public class Addition extends Activity implements OnClickListener{
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_addition);
  
      View results = findViewById(R.id.check_button1);
  
  
  //set event listener
      results.setOnClickListener(this);
  
  
          double myRanNumber1; {
  
          // variable we will use to store a random number
          myRanNumber1 = Math.random(); 
          //myRanNumber generated between 0.000000... &amp; 9.9999...
          myRanNumber1 = myRanNumber1 *10; 
          // myRanNumber between 0.00.. and 9.999..
          myRanNumber1 = (int) myRanNumber1;// myRanNumber between 0 and 9 (fraction chopped off)
          double myRanNumber=(myRanNumber1);
          DecimalFormat df = new DecimalFormat("####");
          String number = df.format(myRanNumber);
          String printnumber = number;
          TextView random = (TextView) findViewById(R.id.TextViewRand);
          random.setText(printnumber); 
          }
  
           double myRanNumber2; 
           {
          // variable we will use to store a random number
          myRanNumber2 = Math.random(); 
          //myRanNumber generated between 0.000000... &amp; 9.9999...
          myRanNumber2 = myRanNumber2 *10; 
          // myRanNumber between 0.00.. and 9.999..
          myRanNumber2 = (int) myRanNumber2;// myRanNumber between 0 and 9 (fraction chopped off)
          double myRanNumber=(myRanNumber2);
          DecimalFormat df = new DecimalFormat("####");
          String number = df.format(myRanNumber);
          String printnumber = number;
          TextView random = (TextView) findViewById(R.id.TextViewRand1);
          random.setText(printnumber); 
          }
  
           double additionRes1 = addition1(myRanNumber1, myRanNumber2);
           Intent theIntent = new Intent(this, Results.class);
  
  
           Bundle b = new Bundle();
           b.putDouble("key", additionRes1);
           theIntent.putExtras(b);
           startActivity(theIntent);
  
  }
  
  private double addition1 (double myRanNumber1, double myRanNumber2)
  
  {
  
      return (double) (myRanNumber1 + myRanNumber2);
  }
  </code></pre>
  
  <p>any help be very much appriciated :)</p>