Question

I am trying to setup an example project that uses Jake Wharton's ActionBarSherlock with ActionBarSherlock-Plugin-Maps. I follow the instructions here and here. I do not necessarily need Fragments. Here is the simple class I created.

package com.example.actionbarsherlock;

import android.os.Bundle;
import com.actionbarsherlock.app.SherlockMapActivity;

public class MainActivity extends SherlockMapActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }
}

Although I tried to follow the exact descriptions I end up with a ClassNotFoundException when I launch the application. Here is the stacktrace.

  Unable to resolve superclass of Lcom/actionbarsherlock/app/SherlockMapActivity; (729)
  Link of class 'Lcom/actionbarsherlock/app/SherlockMapActivity;' failed
  Unable to resolve superclass of Lcom/example/actionbarsherlock/MainActivity; (533)
  Link of class 'Lcom/example/actionbarsherlock/MainActivity;' failed
 D/AndroidRuntime(408): Shutting down VM
  threadid=3: thread exiting with uncaught exception (group=0x4001b188)
  Uncaught handler: thread main exiting due to uncaught exception

  java.lang.RuntimeException: Unable to instantiate activity 
    ComponentInfo{com.example.actionbarsherlock/com.example.actionbarsherlock.MainActivity}: 
    java.lang.ClassNotFoundException: com.example.actionbarsherlock.MainActivity
    in loader dalvik.system.PathClassLoader@44e8ca40

    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4363)
    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:860)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    at dalvik.system.NativeStart.main(Native Method)

  Caused by: java.lang.ClassNotFoundException: com.example.actionbarsherlock.MainActivity 
    in loader dalvik.system.PathClassLoader@44e8ca40

    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:2409)
    ... 11 more
  threadid=7: reacting to signal 3
  Unable to open stack trace file '/data/anr/traces.txt': Permission denied

I tested the library before and created a subclass of SherlockActivity which worked fine. While doing so, I noticed that the same ClassNotFoundException occurs when I forget to configure the android:theme setting in AndroidManifest.xml. Here is the file for both (SherlockActivity and SherlockMapActivity) example projects, just in case:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.actionbarsherlock"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="7"
        android:targetSdkVersion="15" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:theme="@style/Theme.Sherlock"
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest> 

Update:

After adding the uses-library setting as suggested by Raghav Sood and M Mohsin Naeem I run into the following message.

Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY

Here is a screenshot of my projects' setup.

Package Explorer


Edit:

Maybe the .classpath file of my actionbarsherlocktest project helps ...

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="gen"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
    <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
    <classpathentry kind="lib" path="libs/actionbarsherlock-plugin-maps-4.1.0.jar"/>
    <classpathentry kind="output" path="bin/classes"/>
</classpath>

The .classpath file of the library project looks exactly the same.


Solution to the INSTALL_FAILED_MISSING_SHARED_LIBRARY error message.

For some reasons Eclipse always started the emulator that was configured for API level 7 but without the Google API. I could not manage to force it to pick the "map-enabled" emulator. After I deleted the "map-less" emulator the application launched successfully. Do you know how this can happen?


Summary:

Finally, I got it running. Here are some experiences I like to share.

  • Download the latest version of ActionBarSherlock from the website.
  • Do not clone the repository in order to checkout the 4.1.0 tag (9598f2b). It did not work for me.
  • Setup the ActionBarSherlock library project in Eclipse.
  • Update the contained action-support-v4.jar to the latest version.
  • Add the actionbarsherlock-plugin-map-x.y.z.jar to the libs folder of the library project.
  • You do not need to add it to the build path of the library project.
  • Setup your main project and add the library project as a dependency.
  • You do not need to add the action-support-v4.jar or the actionbarsherlock-plugin-map-x.y.z.jar to your main project. It is also not necessary to add any of the .jar files to the build path of the main project.
  • A simple and helpful example to follow is available in the repository.
Was it helpful?

Solution

There are only three reasons you will ever get this error:

  1. The class genuinely doesn't exist. If you are using code from an official example and getting this, make sure you have the latest build of the library
  2. You have not added the jar to your build path. To fix this, right click on the jar in Eclipse, and do Build Path ► Add to Build Path.
  3. Your jar is not in the /libs folder. This happens when you have added the jar to the build path, but newer versions of ADT need it to be in /libs. Put it there and re-add it to the build path.

You should also add

<uses-library android:name="com.google.android.maps" />

To your manifest file.

OTHER TIPS

you miss the Step 8 of this.

<uses-library android:name="com.google.android.maps" />

you need to add this in Manifest File.

Make it like this

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbarsherlock"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="15" />
<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <uses-library android:name="com.google.android.maps" />
    <activity
        android:theme="@style/Theme.Sherlock"
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top