【问题标题】:Adding ActionBarSherlock library creates errors involving android.support.v4添加 ActionBarSherlock 库会创建涉及 android.support.v4 的错误
【发布时间】:2013-01-22 19:37:34
【问题描述】:

我现有的项目使用 Fragments 和 FragmentPagerAdapters 可以顺利运行。但是,添加ActionBarSherlock 库时会出现错误。我发现 [another question] 有同样的问题,但没有答案。

在将库添加到我的项目之前,它看起来像这样,没有错误:

添加库后,我编辑 AndroidManifest.xml 以包含 android:theme="@android:style/Theme.Sherlock",这也会在我的 XML 文件中产生错误。当我将其更改为android:theme="@style/Theme.Sherlock" 时,XML 文件中的错误消失了,但它仍然不起作用,错误如下所示:

编辑:

我已经完成了 CommonsWare 下面的回答中的建议,但我的代码仍然无法正常工作。所有错误都消失了,项目在我的设备上构建甚至启动。但是,当我输入 XML 文件的图形布局时,出现以下错误:

The following classes could not be found:
- android.support.v4.view.PagerTabStrip (Fix Build Path, Edit XML, Create Class)

这就是 XML 文件的样子。请注意,我的 XML 文件没有显示任何错误,但是当我输入 Graphical Layout 选项卡时,会出现上述消息。我没有提到我正在使用ViewPager,但我认为这不会有什么不同。

<?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>

从这里我去选择了Fix Build Path,但仍然无法解决问题。我尝试同时选择library.jarandroid-support-v4.jar,但无济于事。当我尝试打开使用带有这些错误的 XML 文件的任何视图时,程序崩溃。

这是我选择Fix Build Path时得到的窗口:

【问题讨论】:

    标签: android eclipse actionbarsherlock


    【解决方案1】:

    正如您的控制台以红色告诉您的那样,您有两个名为 android-support-v4.jar 的 JAR,它们不是同一个实际文件——它们的大小或内容不同。因此,Android 不知道您想要两个 JAR 中的哪一个。

    通常,简单的答案是从您的项目中删除 JAR。 ActionBarSherlock 有这个 JAR,您的项目将选择它作为将 ActionBarSherlock 附加为库项目的一部分。

    【讨论】:

    • 使用您的答案消除了我的所有错误,并使我的代码能够构建和启动,但它仍然无法正常工作。如果您有机会查看,我已经编辑了我的问题并进行了更新。
    • @JuiCe:ActionBarSherlock 项目中的JAR 太旧,不包含PagerTabStrip。从 SDK 管理器下载当前的 Android 支持库(如果您不在当前支持库中),然后将其 JAR 复制到 ActionBarSherlock 项目的 libs/ 以替换那里的那个。
    • 非常感谢。我尝试在 ActionBarSherlock 项目上运行它,但它已经存在,但没有帮助。然后,我在我的主项目上执行了此操作,并且没有将其移动到 ActionBarSherlock 项目* 的 libs/ 目录*,应用程序现在可以正常工作。我以后会遇到问题吗? support jar 位于这两个位置,就像您之前告诉我的不要这样做一样,但它现在可以工作了。
    • @JuiCe:“支持 jar 位于两个位置,就像您之前告诉我不要这样做一样,但它现在可以工作了”——嗯,它必须是相同版本的 JAR(否则,你原来的错误会返回),所以你应该没问题。
    【解决方案2】:

    SherlockActionBar 中的 android-support-v4.jar 太旧(至少在我下载的项目中)并且它不包含 PagerTabStrip。

    我通过替换actionbarsherlock库项目中的支持​​库来解决它。

    【讨论】:

      【解决方案3】:

      SherlockActionBar 在他的 libs 文件夹中有 android-support-v4.jar。尝试从项目的 lib 文件夹中删除 android-support-v4.jar,以便从 Sherlock 的项目中使用该 jar。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-07-01
        • 2020-08-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-12-21
        相关资源
        最近更新 更多