我刚刚将GreenDroid库添加到我的应用程序中。我用GDActivity扩展了startview,添加了NFF应用程序,并添加到应用程序标记android:name=".logic.NFFApplication"
下的Manifest中。
NFF应用:
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)
我不能100%确定这是否是问题所在,但可能是你忘记覆盖主题了吗?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.
您必须遵循的步骤:
使用简单的:git在您的计算机上下载GreenDroid库克隆http://github.com/cyrilmottier/GreenDroid.git.像往常一样,Git将克隆GreenDroid存储库并创建文件夹GreenDroid包含3个文件夹:GreenDroid:核心库。这是将主要链接到您的代码的代码GreenDroid GoogleAPI:GreenDroid的扩展,包括与GoogleAPI相关的功能(例如GDMapActivity)GDCatalog:演示应用程序。这个项目包含许多代码片段,向您展示如何使用GreenDroid。
自2010年5月以来,ADT插件添加了一个惊人的新功能:能够处理图书馆项目。使用GreenDroid包括将GreenDroid项目作为库应用于您的应用程序。A.关于如何使用库项目的完整说明,请参见Android文档网站。确保你的发展环境使用最新的工具和平台,因为工具和平台的版本不支持使用图书馆项目。
如果你想使用一些谷歌API功能,请确保使用GreenDroid GoogleAPI库。GreenDroid GoogleAPI基于GreenDroid。因此,您不需要链接GreenDroid作为项目的Android库。默认情况下,GreenDroid主题继承自@android:style/theme。如果您的项目继承从另一个主题,你必须修改GreenDroid库你自己(每次更新GreenDroid时都这样做更新会删除您的所有更改-仍在努力克服那个问题)。打开res/values/gd_themes.xml,然后将父主题@android:style/theme替换为您自己的主题。
GreenDroid的许多功能(GDActivity、GDListActivity或例如GDTabActivity)要求您的应用程序是GDApplication,因此请确保您的应用程序是GDApplication班要做到这一点,只需添加android:name="greendroid.app.GDApplication(其中greendroid.app.GDApplication可能会被您自己的类所取代从GDApplication继承)AndroidManifest.xml.
最后,您需要使您的项目使用GreenDroid基本主题。在AndroidManifest.xml中,转到application标签并添加android:theme="@style/theme.GreenDroid"作为新属性。