title: Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.example.myapp.MainActivity
body: <p>Getting an error in logcat when app is launched.Below is the logcat and java code, i have checked this problem in stackover flow but unable to find the solution.</p>
  
  <blockquote>
    <p>MainActivity.Java</p>
  </blockquote>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
      public boolean toasted = false;
  
  @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          if (!((MainActivity) getApplicationContext()).toasted) {  (MainActivity.java:28)
              Toast.makeText(MainActivity.this, "Welcome" , Toast.LENGTH_LONG).show();
              ((MainActivity)getApplicationContext()).toasted = true;
          }
  }
  </code></pre>
  
  <blockquote>
    <p>Logcat</p>
  </blockquote>
  
  <pre><code>Caused by: java.lang.ClassCastException: android.app.Application cannot be cast to com.example.counter.MainActivity
          at com.example.myapp.MainActivity.onCreate(MainActivity.java:28)
  </code></pre>