首先,我是Android新手。 我正在做一个应用程序,我正在实现一个名为HoloEverywhere的库。 这个库在themes.xml中使用了ActionBar Sherlock库。我已导入到我的工作区ActionBar Sherlock,我已将其添加到HoloEverywhere。 接下来,我已将HoloEverywhere添加到我的项目中,但是当我尝试使用它时,我遇到了错误(我尝试使用按钮):
The following classes could not be instantiated:
- com.WazaBe.HoloEverywhere.ButtonHolo (Open Class, Show Error Log)
See the Error Log (Window > Show View) for more details.
Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse.
我把类的路径放在我的布局中,如下所示:
<com.WazaBe.HoloEverywhere.ButtonHolo
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/text" />
如何解决此问题并在我的项目中使用此库?谢谢 :) PS。对不起我的英语,我知道这不是很好。
答案 0 :(得分:39)
请按照以下步骤(摘自博客here)添加ActionBarSherlock
File->New-> Android Project
Create project from existing source
,然后选择browse
到解压缩library
文件夹中的AndroidBarSherlock
文件夹Finish
Properties
。 Android
标题下,您应该看到Library
的一个部分,其中包含IsLibrary
复选框。确保已选中。 AndroidBarSherlock
标题和Android
部分下添加Library
的项目的专家选择Add
。 ActionBarSherlock
库,将其添加到您的项目中按照以下步骤添加HoloEverywhere
File->New-> Android Project
Create project from existing source
,然后选择browse
到解压缩文件夹中的HoloEverywhereLib
文件夹Finish
Properties
。 Android
标题下,您应该看到Library
的一个部分,其中包含IsLibrary
复选框。确保选中并按Add
和之前添加的库ActionBarSherlock
。 按照以下步骤将HoloEverywhere
添加到您的项目中
ActionBarSherlock
和HoloEverywhere
将Android Manifest
更改为以下
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Holo.Theme">
编辑main.xml
以包含Holo主题小部件。
按如下方式更改activity
public class ChkActionBarSherlock extends SherlockActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
答案 1 :(得分:8)
似乎
android:theme="@style/Theme.HoloEverywhereDark.Sherlock"
导致错误。
改变它:
android:theme="@style/Holo.Theme"
在这里:
正确!
答案 2 :(得分:4)
我的项目出现了同样的错误,这就是我所做的,右键单击HoloEverywhere(properties-&gt; android-&gt;库)从列表中删除ActionBarSherlock然后通过单击add重新添加ActionBarSherlock项目,之后清理项目,所有错误都将消失。
答案 3 :(得分:0)
ActionBarSherlock的创建者杰克沃顿在Google+上宣布,ActionBarSherlock的进一步开发已经停止。 ActionBarSherlock 4.4是最新版本,可能会修复错误 - 但不会有任何新功能:
虽然未来几周可能会有一两个点发布,但版本 4.4正在成为The Last Release™。
https://plus.google.com/+JakeWharton/posts/F3HkWY9J8fK
正如我在holoeverywhere issues forum上提出的问题并由开发人员回答:
自v2.0起,HoloEverywhere与ABS没有任何依赖关系
因此,您不应再使用ABS并从项目中删除库并直接替换它或使用Google支持库中的ActionbarCompat替换它。