Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

android - ActionBarSherlock + Maps + Loaders = java.lang.NoClassDefFoundError

Edit: For a detailed how-to, check out my answer.

I'm struggling with it for two days now, hope someone can help.

I'm trying to use the newest ActionBarSherlock (4.0) with a MapView. I knew it's problematic with fragments, but I don't need them in this activity. But I need Loaders and it appears, that to use Loaders I have to extend the FragmentActivity too. No problem, I thought, we have the android-support-v4-googlemaps from Pete Doyle. As suggested on many SO threads and Google Groups I build the ABS with android-support-v4-googlemaps JAR (android-support-v13-r7-googlemaps.jar actually) instead of android-support-v4.jar. Then I used it as a library for my project.

Now, I would like to have my activity this way:

public class BananoutMapActivity extends SherlockFragmentActivity implements LoaderCallbacks<ArrayList<EventItem>>{

The problem:

It compiles, but throws a runtime error: E/AndroidRuntime(29159): java.lang.NoClassDefFoundError: ndl.klimczak.bananout.BananoutMapActivity

Things I've triple checked:

  • both ActionBarSherlock library project and my project are targeted at Google APIs 4.0.3
  • I have <uses-library android:name="com.google.android.maps" /> and I have it in the application tag.
  • I also have the same android-support-v13-r7-googlemaps.jar in the build path of my project
  • I have .BananoutMapActivity declared in my manifest

What is interesting:

  • When I run it on an ICS emulator it works (the error appears on 2.* emulators and my 2.3.7 device), on Honeycomb it would work too probably, it's the question of using the ACL I guess

  • When I remove the implements LoaderCallbacks<ArrayList<EventItem>> part it works too, but this way I'm not able to use LoaderManager

Why on earth the NoClassDefFoundError error and how to get the Loaders working in my MapCapableSherlockEnabledFragmentActivity?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Deprecated: I guess the problem goes away with Google Maps Android API v2. If you decide to use deprecated v1, the solution is below.


So Jake answered the exact problem, but I thought that it would be useful for someone to have a more or less detailed how-to. So how to make ActionBarSherlock work with maps?

I assume you have ActionBarSherlock set up and working as a library project, you can find lots of tutorials on how to do it.

If you just want to use MapActivity with ActionBarSherlock - it's easy:

  1. Download Jake's MapsPlugin https://github.com/JakeWharton/ActionBarSherlock-Plugin-Maps,
  2. Put it in the libs folder of your app and include it in the build path.

If you would like to use MapView with Honeycomb features like Fragments or Loaders:

  1. Download Pete Doyle's android support package with google maps: https://github.com/petedoyle/android-support-v4-googlemaps,
  2. Make a jar (if you download pre-compiled jars it's just a matter of renaming zip to jar, in case you didn't know). You can get the v13 version, it includes v4,
  3. Make a copy of ActionBarSherlock library in the workspace (name it ActionBarSherlockMaps or something like this), just not to mess with the original one, you may have to use it later or something,
  4. Remember to build both ActionBarSherlockMaps and your project against the newest Google APIs. If you use regular Android 4.0.3 without Google APIs it won't work
  5. Put the jar (e.g. android-support-v13-r7-googlemaps.jar) in the libs folder of the new ActionBarSherlockMaps, exclude the android-support-v4.jar from the build path and include android-support-v13-r7-googlemaps.jar
  6. With revision 7, you'll have a compile error in this step in SherlockFragmentActivity. Find protected void supportInvalidateOptionsMenu() and change its visibility to public (this step is not needed in new version of ABS)
  7. Put the same jar in the libs folder of your project, exclude the android-support-v4.jar from the build path and include android-support-v13-r7-googlemaps.jar
  8. Make sure you put <uses-library android:name="com.google.android.maps" /> in the application tag of your Manifest file
  9. Make sure you use the right imports for your fragments, loaders and stuff! You should use e.g. import android.support.v4.app.LoaderManager; insted of import android.app.LoaderManager;
  10. Enjoy ActionBarSherlock + Google Maps + Fragments + Loaders

It's the best workaround for now, until Google puts maps in the compatibility library. I hope they'll do it before 4.* devices outnumber 2.*...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...