java.lang.ClassCastException: org.robolectric.shadows.support.v4.SupportFragmentTestUtil$FragmentUtilActivity cannot be cast to android.support.v7.app.AppCompatActivity

Stack Overflow | Theo | 10 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    Testing Fragments with Robolectric 3.0

    Stack Overflow | 10 months ago | Theo
    java.lang.ClassCastException: org.robolectric.shadows.support.v4.SupportFragmentTestUtil$FragmentUtilActivity cannot be cast to android.support.v7.app.AppCompatActivity

    Root Cause Analysis

    1. java.lang.ClassCastException

      org.robolectric.shadows.support.v4.SupportFragmentTestUtil$FragmentUtilActivity cannot be cast to android.support.v7.app.AppCompatActivity

      at fragments.LoginFragment.onCreateView()
    2. fragments
      LoginFragment.onCreateView
      1. fragments.LoginFragment.onCreateView(LoginFragment.java:64)
      1 frame
    3. Android Support v4
      FragmentManagerImpl$1.run
      1. android.support.v4.app.Fragment.performCreateView(Fragment.java:2074)
      2. android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
      3. android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1286)
      4. android.support.v4.app.BackStackRecord.run(BackStackRecord.java:758)
      5. android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1671)
      6. android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:532)
      6 frames
    4. Android Platform
      Handler.dispatchMessage
      1. android.os.Handler.handleCallback(Handler.java:739)
      2. android.os.Handler.dispatchMessage(Handler.java:95)
      2 frames
    5. Roboelectric HTTP
      ShadowMessageQueue$1.run
      1. org.robolectric.shadows.ShadowMessageQueue.dispatchMessage(ShadowMessageQueue.java:144)
      2. org.robolectric.shadows.ShadowMessageQueue.access$100(ShadowMessageQueue.java:30)
      3. org.robolectric.shadows.ShadowMessageQueue$1.run(ShadowMessageQueue.java:105)
      3 frames
    6. Roboelectric
      Scheduler.postDelayed
      1. org.robolectric.util.Scheduler.runOrQueueRunnable(Scheduler.java:293)
      2. org.robolectric.util.Scheduler.postDelayed(Scheduler.java:143)
      2 frames
    7. Roboelectric HTTP
      ShadowMessageQueue.enqueueMessage
      1. org.robolectric.shadows.ShadowMessageQueue.enqueueMessage(ShadowMessageQueue.java:126)
      1 frame
    8. Android Platform
      Handler.post
      1. android.os.MessageQueue.enqueueMessage(MessageQueue.java)
      2. android.os.Handler.enqueueMessage(Handler.java:631)
      3. android.os.Handler.sendMessageAtTime(Handler.java:600)
      4. android.os.Handler.sendMessageDelayed(Handler.java:570)
      5. android.os.Handler.post(Handler.java:326)
      5 frames
    9. Android Support v4
      BackStackRecord.commit
      1. android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1557)
      2. android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:654)
      3. android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:621)
      3 frames
    10. org.robolectric.shadows
      SupportFragmentTestUtil.startFragment
      1. org.robolectric.shadows.support.v4.SupportFragmentTestUtil.startFragment(SupportFragmentTestUtil.java:17)
      1 frame
    11. team.football.ael
      MainActivityTest.loginFragmentShouldNotBeNull
      1. team.football.ael.MainActivityTest.loginFragmentShouldNotBeNull(MainActivityTest.java:34)
      1 frame
    12. JUnit
      InvokeMethod.evaluate
      1. org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      2. org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      3. org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      4. org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      4 frames
    13. Roboelectric
      RobolectricTestRunner$HelperTestRunner$1.evaluate
      1. org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:527)
      1 frame
    14. JUnit
      RunBefores.evaluate
      1. org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      1 frame
    15. Roboelectric
      RobolectricTestRunner.runChild
      1. org.robolectric.RobolectricTestRunner$2.evaluate(RobolectricTestRunner.java:265)
      2. org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:191)
      3. org.robolectric.RobolectricTestRunner.runChild(RobolectricTestRunner.java:56)
      3 frames
    16. JUnit
      ParentRunner$2.evaluate
      1. org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      2. org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      3. org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      4. org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      5. org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      5 frames
    17. Roboelectric
      RobolectricTestRunner$1.evaluate
      1. org.robolectric.RobolectricTestRunner$1.evaluate(RobolectricTestRunner.java:157)
      1 frame
    18. JUnit
      JUnitCore.run
      1. org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      2. org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      2 frames
    19. IntelliJ junit4 module
      JUnit4IdeaTestRunner.startRunnerWithArgs
      1. com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
      1 frame
    20. IDEA
      AppMain.main
      1. com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
      2. com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
      3. com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
      3 frames