之后实施GreenDroid

时间:2012-04-05 16:18:06

标签: android greendroid

我刚刚将GreenDroid库添加到我的应用程序中。我使用GDActivity扩展了startview并添加了NFFApplication,并在应用程序标记android:name=".logic.NFFApplication"下添加到Manifest中。

NFFAplication:

public class NFFApplication extends GDApplication {

    @Override
    public Class<?> getHomeActivityClass() {
        return NFFApplication.class;
    }

    @Override
    public Intent getMainApplicationIntent() {
        return new Intent(NFFApplication.this,MainView.class);
    }

}

登录活动:

public class LoginView extends GDActivity {

    private ProgressDialog pd = null;
    Editor editor = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setTitle("Movie");
    setActionBarContentView(R.layout.loginlayout);

logcat的:

04-05 16:12:16.714: E/AndroidRuntime(443): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.korn.nff/com.korn.nff.view.LoginView}: android.view.InflateException: Binary XML file line #27: Error inflating class greendroid.widget.ActionBar
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.os.Looper.loop(Looper.java:123)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.app.ActivityThread.main(ActivityThread.java:4363)
04-05 16:12:16.714: E/AndroidRuntime(443):  at java.lang.reflect.Method.invokeNative(Native Method)
04-05 16:12:16.714: E/AndroidRuntime(443):  at java.lang.reflect.Method.invoke(Method.java:521)
04-05 16:12:16.714: E/AndroidRuntime(443):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-05 16:12:16.714: E/AndroidRuntime(443):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-05 16:12:16.714: E/AndroidRuntime(443):  at dalvik.system.NativeStart.main(Native Method)
04-05 16:12:16.714: E/AndroidRuntime(443): Caused by: android.view.InflateException: Binary XML file line #27: Error inflating class greendroid.widget.ActionBar
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-05 16:12:16.714: E/AndroidRuntime(443):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.app.Activity.setContentView(Activity.java:1622)
04-05 16:12:16.714: E/AndroidRuntime(443):  at greendroid.app.GDActivity.ensureLayout(GDActivity.java:187)
04-05 16:12:16.714: E/AndroidRuntime(443):  at greendroid.app.GDActivity.getActionBar(GDActivity.java:265)
04-05 16:12:16.714: E/AndroidRuntime(443):  at greendroid.app.GDActivity.setTitle(GDActivity.java:256)
04-05 16:12:16.714: E/AndroidRuntime(443):  at com.korn.nff.view.LoginView.onCreate(LoginView.java:39)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-05 16:12:16.714: E/AndroidRuntime(443):  ... 11 more
04-05 16:12:16.714: E/AndroidRuntime(443): Caused by: java.lang.reflect.InvocationTargetException
04-05 16:12:16.714: E/AndroidRuntime(443):  at greendroid.widget.ActionBar.<init>(ActionBar.java:130)
04-05 16:12:16.714: E/AndroidRuntime(443):  at java.lang.reflect.Constructor.constructNative(Native Method)
04-05 16:12:16.714: E/AndroidRuntime(443):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
04-05 16:12:16.714: E/AndroidRuntime(443):  ... 24 more
04-05 16:12:16.714: E/AndroidRuntime(443): Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi/title_bar_shadow.9.png from drawable resource ID #0x0
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.content.res.Resources.loadDrawable(Resources.java:1710)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.view.View.<init>(View.java:1850)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.view.View.<init>(View.java:1799)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.view.ViewGroup.<init>(ViewGroup.java:284)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.widget.LinearLayout.<init>(LinearLayout.java:92)
04-05 16:12:16.714: E/AndroidRuntime(443):  at greendroid.widget.ActionBar.<init>(ActionBar.java:134)
04-05 16:12:16.714: E/AndroidRuntime(443):  ... 28 more
04-05 16:12:16.714: E/AndroidRuntime(443): Caused by: java.io.FileNotFoundException: res/drawable-hdpi/title_bar_shadow.9.png
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.content.res.AssetManager.openNonAssetNative(Native Method)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.content.res.AssetManager.openNonAsset(AssetManager.java:390)
04-05 16:12:16.714: E/AndroidRuntime(443):  at android.content.res.Resources.loadDrawable(Resources.java:1702)

1 个答案:

答案 0 :(得分:3)

我不是百分百确定这是否是问题,但是你可能忘记覆盖主题吗? Greendroid需要一个自定义主题才能运行应用程序。

以下是greendroid文档中的行:

You finally need to make your project use the GreenDroid base theme. In your AndroidManifest.xml, go to the application tag and add android:theme="@style/Theme.GreenDroid" as a new attribute.

您必须遵循的步骤:

  1. 使用简单的git在计算机上下载GreenDroid库 克隆http://github.com/cyrilmottier/GreenDroid.git。像往常一样,Git 将克隆GreenDroid存储库并创建一个文件夹GreenDroid 包含3个文件夹:    GreenDroid:核心库。这是主要链接到您的代码的代码    GreenDroid-GoogleAPIs:GreenDroid的扩展包括与Google API相关的功能(例如GDMapActivity)    GDCatalog:演示应用程序。这个项目包含很多代码片段,向您展示如何使用GreenDroid。

  2. 自2010年5月以来,ADT插件增加了一项惊人的新功能: 能够使用图书馆项目。使用GreenDroid包含 将GreenDroid项目作为库应用于您的应用程序。一个 有关如何使用库项目的完整描述 Android文档网站。确保你的发展 环境使用最新的工具和平台,因为旧的 这些工具和平台的版本不支持构建 图书馆项目。

  3. 如果您想使用某些Google API功能,请确保您使用此功能 使用GreenDroid-GoogleAPIs库。 GreenDroid-GoogleAPIs是 基于GreenDroid。因此,您无需链接GreenDroid 作为您项目的Android库。默认情况下,GreenDroid 主题继承自@android:style / Theme。如果您的项目继承 从不同的主题,你将不得不修改GreenDroid库 自己(并且每次更新GreenDroid时都这样做) 更新删除所有更改 - 仍在努力 克服这个问题)。打开res / values / gd_themes.xml和 用自己的主题替换父主题@android:style / Theme。

  4. 很多GreenDroid的功能(GDActivity,GDListActivity或 例如GDTabActivity)要求您的应用程序是一个 GDApplication所以请确保您的应用程序是GDApplication 类。为此,只需添加即可 android:name =“greendroid.app.GDApplication(其中 greendroid.app.GDApplication可以替换为您自己的类 继承自GDApplication)在你的应用程序标签中 的AndroidManifest.xml。

  5. 您最终需要使您的项目使用GreenDroid基本主题。 在AndroidManifest.xml中,转到应用程序标记并添加 android:theme =“@ style / Theme.GreenDroid”作为新属性。