My existing project runs smoothly using Fragments and FragmentPagerAdapters. However, when adding the ActionBarSherlock
library errors appear. I have found [another question] with the same problems, but there are no answers.
Before adding the library to my project, it looks like this with no errors:
After adding the library, I edit the AndroidManifest.xml
to include android:theme="@android:style/Theme.Sherlock"
, which produces an error in my XML file as well. When I change it to android:theme="@style/Theme.Sherlock"
, the error in the XML file disappears but it still doesn't work and the errors look like this:
EDIT:
I have done what was suggested in CommonsWare's answer below, but my code is still not working properly. All errors go away and the project builds and even launches on my device. However when I enter the Graphical layout of my XML files I get the following error:
The following classes could not be found:
- android.support.v4.view.PagerTabStrip (Fix Build Path, Edit XML, Create Class)
This is what the XML file looks like. Note that my XML file shows no errors, but when I enter the Graphical Layout
tab the above message appears. I had not mentioned that I am using a ViewPager
but I didn't think it would make a difference.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/wavesMonitorMenuBar"
style="@android:style/ButtonBar"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/menu_back" />
<Button
android:id="@+id/readButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/menu_read" />
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="@+id/statusPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_above="@id/wavesMonitorMenuBar" >
<android.support.v4.view.PagerTabStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#9E9E9E"
android:textColor="#fff"
android:paddingTop="4dp"
android:paddingBottom="4dp" />
</android.support.v4.view.ViewPager>
</RelativeLayout>
From here I went to chose Fix Build Path
but still couldn't solve the problem. I tried selecting both library.jar
and android-support-v4.jar
but to no avail. The program crashes when I try to open any views that use the XML files with these errors.
This is the window I get when I choose Fix Build Path
:
SherlockActionBar has android-support-v4.jar in his libs folder. Try to remove android-support-v4.jar from your project's lib folder, so that jar will be used from Sherlock's project.
The android-support-v4.jar in SherlockActionBar is too old(at least in my downloaded project) and it does not contain PagerTabStrip.
I resolve it by replacing the support library in actionbarsherlock library project.
As your console is telling you in red, you have two JARs, named
android-support-v4.jar
, and they are not the same actual file -- their sizes or contents differ. Hence, Android does not know which of the two JARs you want.Usually, the simple answer is to delete the JAR from your project. ActionBarSherlock has this JAR, and your project will pick that one up as part of having ActionBarSherlock attached as a library project.