title: Accessing a variable from one class that is located in another class
body: <p>Iv been stuck on this bug, in my android app, for about 3 weeks now. Its killing me... :(. Can someone please fix the code for me (its a small error), and then I can learn from it. Basically, I have the MainActivity class that holds a variable "dblCountValue". I want to access the variable in the Withdraw class. Here is my code:</p>
  
  <p>CLASS: MainActivity</p>
  
  <pre><code>package com.mycash.borgjake.mycash;
  
  import android.content.Intent;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  
  import android.widget.Button;
  import android.widget.TextView;
  
  import android.view.View;
  
  import com.google.android.gms.ads.AdListener;
  import com.google.android.gms.ads.AdRequest;
  import com.google.android.gms.ads.AdView;
  import com.google.android.gms.ads.InterstitialAd;
  
  import static com.mycash.borgjake.mycash.R.styleable.View;
  
  public class MainActivity extends AppCompatActivity {
  
  private InterstitialAd mInterstitial;
  
  
  Button btnClick;
  Button btnWithdraw;
  
  TextView txtBalance;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      AdView adView = (AdView)findViewById(R.id.adView);
      AdRequest adRequest = new AdRequest.Builder()
              .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
              .build();
      adView.loadAd(adRequest);
  
      btnClick = (Button) findViewById(R.id.button);
  
      txtBalance = (TextView) findViewById(R.id.textView);
  
      btnClick.setOnClickListener(new View.OnClickListener() {
  
          @Override
          public void onClick(View v){
                  String countValue = txtBalance.getText().toString();
                  int dblCountValue = Integer.parseInt(countValue);
  
                  if (mInterstitial.isLoaded()) {
                      mInterstitial.show();
                  }
  
                  //mInterstitial.loadAd(request);
  
                  dblCountValue++;
                  txtBalance.setText(String.valueOf(dblCountValue));
  
          }
      });
  
      mInterstitial = new InterstitialAd(this);
      mInterstitial.setAdUnitId("...");
      AdRequest request = new AdRequest.Builder()
              .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
              .build();
      mInterstitial.loadAd(request);
  
  }
  
  public void onButtonClick(View v) {
      if(v.getId() == R.id.button2) {
          Intent i = new Intent(MainActivity.this, Withdraw.class);
          startActivity(i);
      }
    }
  }
  </code></pre>
  
  <p>CLASS: Withdraw</p>
  
  <pre><code>package com.mycash.borgjake.mycash;
  
  import android.app.Activity;
  import android.app.AlertDialog;
  import android.os.Bundle;
  import android.view.View;
  
  import com.google.android.gms.ads.AdRequest;
  import com.google.android.gms.ads.AdView;
  
  public class Withdraw extends Activity {
  
  MainActivity mainActivityObject = new MainActivity();
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.withdraw);
  
      AdView adView = (AdView) findViewById(R.id.adView2);
      AdRequest adRequest = new AdRequest.Builder()
              .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
              .build();
      adView.loadAd(adRequest);
  }
  
  public void showAlert(View view) {
      AlertDialog.Builder myAlert = new AlertDialog.Builder(this);
  
      String messageWithdraw;
      String aWithdraw;
      String dWithdraw;
      aWithdraw = "Congradulations! Your payment is being processed";
      dWithdraw = "Sorry! Please try again when you reach 100 points ($10)";
  
  
  
      dblCountValue = mainActivityObject.dblCountValue;      // &lt;-- Error
  
      if (dblCountValue &gt; 100) {                           // &lt;-- Error
          myAlert.setMessage(aWithdraw)                   
                  .create();                             
          myAlert.show();                               
      } else {                                         
          myAlert.setMessage(dWithdraw)               
                  .create();                         
          myAlert.show();                           
      }                                            
  
    }
  }
  </code></pre>
  
  <p>Thanks a lot in advance :)</p>