添加ActionBarSherlock库会产生涉及android.support.v4的错误 [英] Adding ActionBarSherlock library creates errors involving android.support.v4

查看:320
本文介绍了添加ActionBarSherlock库会产生涉及android.support.v4的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的现有项目使用Fragments和FragmentPagerAdapters平滑运行。但是,当添加 ActionBarSherlock 库错误出现时。我发现了另外一个问题,但也没有答案。



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





添加库后,我编辑 AndroidManifest.xml 包含 android:theme =@ android:style / Theme.Sherlock,这会在我的XML文件也是。当我将其更改为 android:theme =@ style / Theme.Sherlock时,XML文件中的错误消失,但仍然不起作用,错误看起来像这个:





编辑:



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

 找不到以下类:
- android.support.v4.view.PagerTabStrip(修复构建路径,编辑XML,创建类)

这是XML文件的样子。请注意,我的XML文件没有显示错误,但是当我输入图形布局选项卡时,将显示上述消息。我没有提到我正在使用 ViewPager ,但我并不认为会有所作为。

 <?xml version =1.0encoding =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 =horizo​​ntal>

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

从这里我去了选择修复构建路径但仍然无法解决问题。我尝试选择 library.jar android-support-v4.jar 但无效。当我尝试打开使用这些错误的XML文件的任何视图时,程序崩溃。



这是当我选择修复构建路径时获得的窗口:



解决方案

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



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


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:

解决方案

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.

这篇关于添加ActionBarSherlock库会产生涉及android.support.v4的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆