Begginer ClassNotFoundException

731 views
Skip to first unread message

Fab

unread,
Dec 23, 2011, 8:58:31 AM12/23/11
to ActionBarSherlock
Hello,

I'm french and I try to use Sherlock Action Bar in my application but
I think I made a beginner mistake. Maybe you
will found easilly what I forgot ?

The activity :
...
import android.support.v4.app.FragmentActivity;

public class MainActivity extends FragmentActivity
{

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


The AndroidManifest.xml :
<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage.activity" android:versionCode="12"
android:versionName="1.10">

<application android:icon="@drawable/ic_launcher"
android:label="@string/application_name" >
<activity android:name=".MainActivity"
android:launchMode="singleTask"
android:theme="@style/Theme.Sherlock.Light">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

<!-- min sdk version SDK 4 = Android 1.6 -->
<!-- target 13=3.2 for ActionBarSherlock -->
<uses-sdk android:minSdkVersion="4" targetSdkVersion="13" />
...

But application crashes on launch :
12-22 22:13:28.774: E/AndroidRuntime(402): Caused by:
java.lang.ClassNotFoundException:
com.mypackage.activity.MainActivity in loader
dalvik.system.PathClassLoader[/data/app/com.mypackage.activity-2.apk]

Thank you.

Bill Mote

unread,
Dec 23, 2011, 1:15:13 PM12/23/11
to actionba...@googlegroups.com

Check the names of your activities against your manifest.

Fabien

unread,
Dec 23, 2011, 2:02:37 PM12/23/11
to actionba...@googlegroups.com
If I replace

public class MainActivity extends FragmentActivity
by
public class MainActivity extends Activity

application works.

Jake Wharton

unread,
Dec 23, 2011, 2:05:19 PM12/23/11
to actionba...@googlegroups.com
Paste the full log including lines above the actual stack trace. I'm willing to bet your APK doesn't include the ActionBarSherlock classes which means the classloader can't resolve the superclass which will cause it to ignore MainActivity altogether.

Make sure you're including ActionBarSherlock using whatever build system you are using.

---
Jake Wharton
http://about.me/jakewharton

Bill Mote

unread,
Dec 23, 2011, 2:24:42 PM12/23/11
to actionba...@googlegroups.com

Did you add the ABS as a library in your project?

Fabien

unread,
Dec 23, 2011, 4:09:52 PM12/23/11
to actionba...@googlegroups.com
Thank you for your help.

I don't know why but today, I see for the first time my application
with the action bar !

Eclipse console displays :
[2011-12-23 22:06:02 - MyApplication] ------------------------------
[2011-12-23 22:06:02 - MyApplication] Android Launch!
[2011-12-23 22:06:02 - MyApplication] adb is running normally.
[2011-12-23 22:06:02 - MyApplication] Performing
com.fabreax.android.kartingtools.activity.MainActivity activity launch
[2011-12-23 22:06:03 - MyApplication] Uploading KartingTools.apk onto
device 'emulator-5554'
[2011-12-23 22:06:26 - MyApplication] Installing KartingTools.apk...
[2011-12-23 22:06:32 - MyApplication] Success!
[2011-12-23 22:06:32 - actionbarsherlocklibrary] Could not find
actionbarsherlocklibrary.apk!
[2011-12-23 22:06:32 - MyApplication] Starting activity
com.mypackage.activity.MainActivity on device emulator-5554
[2011-12-23 22:06:33 - MyApplication] ActivityManager: Starting:
Intent { act=android.intent.action.MAIN
cat=[android.intent.category.LAUNCHER]
cmp=com.mypackage.activity/.MainActivity }

I don't know why it works but displays "Could not find
actionbarsherlocklibrary.apk" !

Fab

Fabien

unread,
Dec 23, 2011, 4:34:29 PM12/23/11
to actionba...@googlegroups.com
I don't understand, the exception came back.

Which version must I select in My project > Properties > Android tab ?

I tried 4 (1.6), 13 Normal (3.2) and 13 API (3.2).

Jake Wharton

unread,
Dec 23, 2011, 4:37:04 PM12/23/11
to actionba...@googlegroups.com
You need to compile with Android 3.2 and have the ActionBarSherlock project listed in the "Library" section at the bottom of the preference screen.

Fabien

unread,
Dec 24, 2011, 6:05:14 AM12/24/11
to actionba...@googlegroups.com
Hello,

I updated all my Eclipse plugins and SDKs (via ADT manager).

ActionBarSherlock project is in library section of my android project
properties screen.
I set Android 3.2 in this same screen and <uses-sdk
android:minSdkVersion="4" targetSdkVersion="13" /> in my manifest
file.

I use a 2.3 Android emulator (and device).

Some times it works, sometimes I have this complete stack trace :
12-24 10:48:39.406: E/AndroidRuntime(349): FATAL EXCEPTION: main
12-24 10:48:39.406: E/AndroidRuntime(349): java.lang.RuntimeException:
Unable to instantiate activity
ComponentInfo{com.mypackage.activity/com.mypackage.activity.MainActivity}:
java.lang.ClassNotFoundException: com.mypackage.MainActivity in loader
dalvik.system.PathClassLoader[/data/app/com.mypackage.activity-2.apk]
12-24 10:48:39.406: E/AndroidRuntime(349): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
12-24 10:48:39.406: E/AndroidRuntime(349): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
12-24 10:48:39.406: E/AndroidRuntime(349): at
android.app.ActivityThread.access$1500(ActivityThread.java:117)
12-24 10:48:39.406: E/AndroidRuntime(349): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
12-24 10:48:39.406: E/AndroidRuntime(349): at
android.os.Handler.dispatchMessage(Handler.java:99)
12-24 10:48:39.406: E/AndroidRuntime(349): at
android.os.Looper.loop(Looper.java:123)
12-24 10:48:39.406: E/AndroidRuntime(349): at
android.app.ActivityThread.main(ActivityThread.java:3683)
12-24 10:48:39.406: E/AndroidRuntime(349): at
java.lang.reflect.Method.invokeNative(Native Method)
12-24 10:48:39.406: E/AndroidRuntime(349): at
java.lang.reflect.Method.invoke(Method.java:507)
12-24 10:48:39.406: E/AndroidRuntime(349): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-24 10:48:39.406: E/AndroidRuntime(349): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-24 10:48:39.406: E/AndroidRuntime(349): at
dalvik.system.NativeStart.main(Native Method)
12-24 10:48:39.406: E/AndroidRuntime(349): Caused by:


java.lang.ClassNotFoundException: com.mypackage.activity.MainActivity
in loader dalvik.system.PathClassLoader[/data/app/com.mypackage.activity-2.apk]

12-24 10:48:39.406: E/AndroidRuntime(349): at
dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
12-24 10:48:39.406: E/AndroidRuntime(349): at
java.lang.ClassLoader.loadClass(ClassLoader.java:551)
12-24 10:48:39.406: E/AndroidRuntime(349): at
java.lang.ClassLoader.loadClass(ClassLoader.java:511)
12-24 10:48:39.406: E/AndroidRuntime(349): at
android.app.Instrumentation.newActivity(Instrumentation.java:1021)
12-24 10:48:39.406: E/AndroidRuntime(349): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
12-24 10:48:39.406: E/AndroidRuntime(349): ... 11 more

I always have this in console even if it works :
[2011-12-24 12:00:00 - actionbarsherlocklibrary] Could not find
actionbarsherlocklibrary.apk!

Fab

Fabien

unread,
Dec 24, 2011, 11:02:26 AM12/24/11
to actionba...@googlegroups.com
[2011-12-24 16:21:55 - actionbarsherlocklibrary] Could not find
actionbarsherlocklibrary.apk!
already appears but it works fine now (I don't know why).

I have a little question when I try to customize the action bar :
I to display the default icon and the arrow (homeAsUp).

getSupportActionBar().setDisplayHomeAsUpEnabled(true); seems to work
on 2.3 but not 3.2 version.

<item name="abDisplayOptions">useLogo|homeAsUp|showHome|showTitle</item>
doesn't work for homeAsUp (2.3 and 3.2 versions).

When I touch the logo, nothing appears, what must I do ?

Thank you again.

Fab

Jens Zalzala

unread,
Jan 8, 2012, 3:02:30 PM1/8/12
to ActionBarSherlock
I'm running into the same issue. The only way to fix it is to remove
the library, then add it back. Problem is I have to do this several
times a day now.
Any ideas?

On Dec 24 2011, 8:02 am, Fabien <fabr...@gmail.com> wrote:
> [2011-12-24 16:21:55 - actionbarsherlocklibrary] Could not find
> actionbarsherlocklibrary.apk!
> already appears but it works fine now (I don't know why).
>
> I have a little question when I try to customize the action bar :
> I to display the default icon and the arrow (homeAsUp).
>
> getSupportActionBar().setDisplayHomeAsUpEnabled(true); seems to work
> on 2.3 but not 3.2 version.
>
> <item name="abDisplayOptions">useLogo|homeAsUp|showHome|showTitle</item>
> doesn't work for homeAsUp (2.3 and 3.2 versions).
>
> When I touch the logo, nothing appears, what must I do ?
>
> Thank you again.
>
> Fab
>

Jake Wharton

unread,
Jan 8, 2012, 5:17:41 PM1/8/12
to actionba...@googlegroups.com
Make sure your ADT and Eclipse ADT plugin are up to date. I haven't had to remove and add the library projects anymore since v16.0.1.

Jonathan Steele

unread,
Jan 8, 2012, 5:22:28 PM1/8/12
to actionba...@googlegroups.com
It is best to do full clean first before you are compiling the sources.
Reply all
Reply to author
Forward
0 new messages