title: MockitoException: Failed to mock class com.example.example.test.MainActivity
body: <p>I tried to install <strong>Mockito</strong> and got that <strong>error message</strong>. I'll be back to add my own answer when I get it.</p>
  
  <p>It happens for both the real MainActivity, and its derivative MockActivity, test-side.</p>
  
  <p>It also happens in a new Android project, with android version 4.3, and a very recent Eclipse. Plus Mockito 1.9.5. Any questions, maintainers?</p>
  
  <p>The test case is trivial, and uses <code>ActivityUnitTestCase&lt;MainActivity&gt;</code>.</p>
  
  <p>Has anyone seen this kinda stack trace before?</p>
  
  <pre><code>org.mockito.exceptions.base.MockitoException: Failed to mock class com.example.example.test.MockActivity
  
  at com.example.example.test.SmartPhinsTest.test_mockito_mocks_activities(ExampleTest.java:39)
  
  at java.lang.reflect.Method.invokeNative(Native Method)
  at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
  at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
  </code></pre>
  
  <p>And could someone found a testing-framework tag already?</p>
  
  <p>The (trivial) code snip is:</p>
  
  <pre><code>package com.example.example.test;
  
  import java.io.File;
  
  import android.app.Instrumentation;
  import android.content.Context;
  import android.content.Intent;
  import android.test.ActivityUnitTestCase;
  
  import com.example.example.MainActivity;
  
  import static org.mockito.Mockito.*;
  
  public class ActivityTests extends ActivityUnitTestCase&lt;MainActivity&gt; {
      public ActivityTests(Class&lt;MainActivity&gt; activityClass) {
          super(activityClass);
      }
      public ActivityTests() {
          super(MainActivity.class);
      }
      Activity activity;
      Context targetContext;
      Intent intent;
  
      @Override
      protected void setUp() throws Exception {
          targetContext = getInstrumentation().getTargetContext();
          intent = new Intent(targetContext, MainActivity.class);
          super.setUp();
          startActivity(intent, null, null);
          activity = getActivity();
      }                
      public void test_mockito_mocks_activities() {            
          Context context = activity.getApplicationContext();
          File cacheDir = context.getCacheDir();
          String path = cacheDir.getPath();
          System.setProperty("dexmaker.dexcache", path); // "/storage/sdpath");
          MainActivity mockActivity = mock(MainActivity.class);
      }
  }
  </code></pre>
  
  <p>I also added <code>android.permission.WRITE_EXTERNAL_STORAGE</code> to both <code>AndroidManifest.xml</code> files. And, although most of the examples use <code>ActivityInstrumentationTestCase2</code>, it refuses to work for me - even in a greenfield project on another platform.</p>
  
  <p>That fairly consistently gives me:</p>
  
  <pre><code>E/dalvikvm(3576): Could not find class 'android.app.LoaderManagerImpl', referenced from method MainActivity_Proxy.getLoaderManager
  E/dalvikvm(3576): Could not find class 'android.app.Activity$NonConfigurationInstances', referenced from method MainActivity_Proxy.retainNonConfigurationInstances
  </code></pre>