title: java.lang.ClassCastException: MainActivity cannot be cast to android.support.v4.app.FragmentActivity
body: <p>I have a piece of code that tries to query the YouTube Data API to get the MetaData of a youtube video, using as a parameter the videoID. To be able to access the YouTube Data API server, the program executes the imposed transactions and permissions.
  To be able to access the YouTube Data API, the code invokes a Dialog window with the message: "This app needs your Google account (via Contacts)":</p>
  
  <pre><code>public class LMMoviesMainActivity extends AppCompatActivity
      implements EasyPermissions.PermissionCallbacks {... 
  
  
  // Relevant part of the method of the Interface: EasyPermissions:
  
  EasyPermissions.requestPermissions(
                  this,
                  "This app needs to access your Google account (via Contacts).",
                  REQUEST_PERMISSION_GET_ACCOUNTS,
                  Manifest.permission.GET_ACCOUNTS);
  </code></pre>
  
  <p>The window has Ok and Cancel buttons. After pressing Ok, the App crashes. The LogCat is:</p>
  
  <pre><code>11-18 10:27:08.460 4566-4566/com.languagematerial.lmmovies E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                   Process: com.languagematerial.lmmovies, PID: 4566
                                                                               java.lang.ClassCastException: com.languagematerial.lmmovies.LMMoviesMainActivity cannot be cast to android.support.v4.app.FragmentActivity
                                                                                   at pub.devrel.easypermissions.RationaleDialogClickListener.onClick(RationaleDialogClickListener.java:57)
                                                                                   at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:162)
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                   at android.os.Looper.loop(Looper.java:148)
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  11-18 10:27:08.461 1642-2985/system_process W/ActivityManager:   Force finishing activity com.languagematerial.lmmovies/.LMMoviesMainActivity
  11-18 10:27:08.463 1259-1720/? D/PermissionCache: checking android.permission.READ_FRAME_BUFFER for uid=1000 =&gt; granted (109 us)
  11-18 10:27:08.463 1259-1720/? D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 520192
  
  
  [ 11-18 10:27:08.466  1642: 2985 D/         ]
                                                   HostConnection::get() New Host Connection established 0x9cb5b9c0, tid 2985
  11-18 10:27:08.484 1259-1720/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
  11-18 10:27:08.484 1642-4704/system_process D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
  </code></pre>
  
  <p>The line: RationaleDialogClickListener.java refers to a file which is part of a Library called: pub.devrel:easypermissions-0.3.0</p>
  
  <p>The code in that Library file in the Line number 57 is:</p>
  
  <pre><code>ActivityCompat.requestPermissions((FragmentActivity) mHost, mConfig.permissions, mConfig.requestCode);
  </code></pre>
  
  <p>This RationaleDialogClickListener.java file cannot be modified because it is ONLY READABLE. And even if I could modify it, I have no idea what to put instead!</p>
  
  <p>Also, my own App never uses fragments: The calling code is located in the MainActivity (In case that fact could be relevant).</p>
  
  <p>There are similar cases of this Cast error, but none has a satisfactory answer. Any ideas or suggestions on how to proceed? Thanks</p>