簡體   English   中英

添加ActionBarSherlock庫會產生涉及android.support.v4的錯誤

[英]Adding ActionBarSherlock library creates errors involving android.support.v4

我現有的項目使用Fragments和FragmentPagerAdapters可以平穩運行。 但是,添加ActionBarSherlock庫時會出現錯誤。 我發現[另一個問題]也有同樣的問題,但是沒有答案。

在將庫添加到我的項目之前,它看起來像這樣,沒有錯誤:

在此處輸入圖片說明

添加該庫之后,我將AndroidManifest.xml編輯為包含android:theme="@android:style/Theme.Sherlock" ,這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時看到的窗口:

在此處輸入圖片說明

正如您的控制台用紅色告訴您那樣,您有兩個JAR,名為android-support-v4.jar ,它們不是相同的實際文件-它們的大小或內容不同。 因此,Android不知道您想要兩個JAR。

通常,簡單的答案是從項目中刪除JAR。 ActionBarSherlock具有此JAR,並且在將ActionBarSherlock作為庫項目附加到您的項目中時,您的項目會選擇該JAR。

SherlockActionBar中的android-support-v4.jar太舊(至少在我下載的項目中),並且其中不包含PagerTabStrip。

我通過替換actionbarsherlock庫項目中的支持​​庫來解決它。

SherlockActionBar在他的libs文件夾中有android-support-v4.jar。 嘗試從項目的lib文件夾中刪除android-support-v4.jar,以便從Sherlock的項目中使用jar。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM