title: Android: Unable to instantiate activity / ClassNotFoundException
body: <p>I recently published an app to the market and I'm now getting an error by some user, the app presumably crashes right when it starts. Unfortunately I can't contact him directly and the app works fine in the emulator as well as on my phone (and some friends' phones).<br />EDIT: I guess that this happens to more than one user as I received comments in the market like "crashes on start" or "doesn't work". I only received this one stacktrace but there's no info about the configuration, device, Android version, etc.</p>
  
  <p>The app is a simple soundboard, so there's really no magic involved, but I can't get why it fails on some phones. Here's the stack trace I'm getting, I hope anybody can help me out:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.my.app/com.my.app.SoundMachine}: java.lang.ClassNotFoundException: com.my.app.SoundMachine in loader dalvik.system.PathClassLoader[/mnt/asec/com.my.app-1/pkg.apk]
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:123)
  at android.app.ActivityThread.main(ActivityThread.java:4627)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:521)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
  at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.ClassNotFoundException: com.my.app.SoundMachine in loader dalvik.system.PathClassLoader[/mnt/asec/com.my.app-1/pkg.apk]
  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
  ... 11 more
  </code></pre>
  
  <p>These are the first couple of lines from my activity:</p>
  
  <pre><code>public class SoundMachine extends Activity {
    private SoundManager mSoundManager;
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  </code></pre>
  
  <p>EDIT: This is the (almost) complete onCreate:</p>
  
  <pre><code>  @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      mSoundManager = new SoundManager();
      mSoundManager.initSounds(getBaseContext());
  
      int counter = 0;
      for (Integer soundFile : soundFiles) {
        counter++;
        mSoundManager.addSound(counter, soundFile);
      }
  
      ImageButton SoundButton1 = (ImageButton) findViewById(R.id.sound1);
      SoundButton1.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
          mSoundManager.playSound(1);
        }
      });
      SoundButton1.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
          saveSoundChoice(soundFiles[0], soundNames[0]);
          return true;
        }
      });
  
  (...more of this...)
  
      Button StopButton = (Button) findViewById(R.id.stopbutton);
      StopButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
          mSoundManager.stopAll();
        }
      });
    }
  </code></pre>
  
  <p>And here's my manifest:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.my.app" android:installLocation="preferExternal"
      android:versionCode="9" android:versionName="1.2"&gt;
      &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
          &lt;activity android:name=".SoundMachine" android:label="@string/app_name"
              android:screenOrientation="portrait"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
      &lt;uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" /&gt;
  &lt;/manifest&gt;
  </code></pre>
  
  <p>So all possible errors I already read about here and in some forums don't apply to my app.</p>
  
  <ul>
  <li>The activity is present in the manifest.</li>
  <li>The super-method is called in the overriden method.</li>
  <li>The ContentView is set before accessing elements in the view.</li>
  </ul>
  
  <p>I know it's hard to pinpoint the source of an error without being able to reproduce it, but maybe somebody has a bright idea and can help me out.</p>
  
  <p>Some questions:</p>
  
  <ul>
  <li><strike>Do I need the "intent"-part in the manifest? Eclipse created it when I created the project.</strike> (Yes, according to Mayra)</li>
  <li><strike>Should the super-method be called where it is?</strike> (Yes, according to Mayra)</li>
  </ul>
  
  <p>EDIT: The main question that remains now is: How come the path in PathClassLoader is different from my package-name? The page John J Smith posted seems to deal with the same problem, but I don't understand the fix that was applied there.</p>
  
  <p>Thanks, Select0r</p>