gpt4 book ai didi

android - 扩展 ActionBarActivity 导致错误

转载 作者:行者123 更新时间:2023-11-29 16:02:35 25 4
gpt4 key购买 nike

我有一个扩展 FragmentActivity 和导入 android 库 v4 的类。现在我想在我的 Activity 中实现 Navigation Drawer,我想扩展 ActionBarActivity。由于 ActionBarActivity 还实现了 FragmentActivity,我被告知我仍然可以在我的类中将 fragment 与 ActionBarActivity 一起使用。

所以我开始使用 ActionBarActivity,首先是导入 v7 库。我从

复制了文件

C:\Program Files\Android Developer Tools\sdk\extras\android\support\v7

到工作区我的应用程序文件夹中的 libs 文件夹。

现在我的 Eclipse 没有检测到我的类扩展 ActionBarActivity 的错误。但是,当我运行它时,它崩溃了。

这是在我的 LogCat 上找到的一些信息(我想知道它是否对任何时候都有帮助):

03-27 16:30:12.113: E/AndroidRuntime(8130): FATAL EXCEPTION: main
03-27 16:30:12.113: E/AndroidRuntime(8130): Process: com.anggrian.readee, PID: 8130
03-27 16:30:12.113: E/AndroidRuntime(8130): java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:107)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
03-27 16:30:12.113: E/AndroidRuntime(8130): at com.anggrian.readee.MainActivity.onCreate(MainActivity.java:37)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.Activity.performCreate(Activity.java:5231)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2169)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2265)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.ActivityThread.access$800(ActivityThread.java:145)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.os.Handler.dispatchMessage(Handler.java:102)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.os.Looper.loop(Looper.java:136)
03-27 16:30:12.113: E/AndroidRuntime(8130): at android.app.ActivityThread.main(ActivityThread.java:5081)
03-27 16:30:12.113: E/AndroidRuntime(8130): at java.lang.reflect.Method.invokeNative(Native Method)
03-27 16:30:12.113: E/AndroidRuntime(8130): at java.lang.reflect.Method.invoke(Method.java:515)
03-27 16:30:12.113: E/AndroidRuntime(8130): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)
03-27 16:30:12.113: E/AndroidRuntime(8130): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-27 16:30:12.113: E/AndroidRuntime(8130): at dalvik.system.NativeStart.main(Native Method)

我想知道是否可以得到任何帮助,谢谢!

@Raghunandan 这是我的 styles.xml:

<resources>

<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.

-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.

-->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

<!-- MY OWN THEME -->
<style name="DarkGreyTheme" parent="@android:style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/DarkGreyActionBar</item>
</style>

<style name="DarkGreyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#b6b6b6</item>
</style>

<!-- MY OWN THEME -->
<style name="OrangeTheme" parent="@android:style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">@style/OrangeActionBar</item>
</style>

<style name="OrangeActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#ff6400</item>
</style>

</resources>

AndroidManifest.xml 中未使用 AppTheme,因此请忽略它们。我曾经在我的自定义主题中使用@android:style/Theme.Holo.Light,但由于我已经在我的主类中扩展了 ActionBarActivity,LogCat 指示我需要使用 AppCompat 主题。

最佳答案

java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$styleable

AppCompat 是一个带有资源的库项目。您需要在您的 Android 项目中引用 AppCompat

您也可以查看我之前回答过的类似问题。现在找到了

No resource found that matches the given name '@style/Theme.AppCompat.Light'

您可以按照以下链接中的@添加带有资源的库的步骤

https://developer.android.com/tools/support-library/setup.html

从sdk manager下载支持库

enter image description here

将库项目导入工作区。可以找到@

sdk>/extras/android/support/v7/appcompat/

导入后

enter image description here

右键单击您的 Android 项目。转到属性。选择安卓。单击添加并选择 AppCompact。单击确定。成功后您应该会看到一个绿色勾号。

引用之后

enter image description here

你已经完成了。

关于android - 扩展 ActionBarActivity 导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22683607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com