1

I have a class that were extending FragmentActivity and importing android library v4. Now that I want to implement Navigation Drawer in my activity, I'd like to extend ActionBarActivity. And since ActionBarActivity also implements FragmentActivity, I've been told that I could still use fragments in my class with ActionBarActivity.

So I start working with ActionBarActivity, first by importing the v7 library. I copied the file from

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

to the libs folder in my app folder on workspace.

Now my Eclipse detects no errors with my class extending ActionBarActivity. However when I run it, it crashes.

Here's some information found at my LogCat (I wonder if it coulp help at any point):

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)

I wonder if I could get any help, thanks!

@Raghunandan here's my 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>

the AppTheme is not used in AndroidManifest.xml so just ignore them. I used to use @android:style/Theme.Holo.Light in my custom themes but since I already extending ActionBarActivity in my main class, LogCat indicates I need to use AppCompat Theme.

Hendra Anggrian
  • 5,780
  • 13
  • 57
  • 97

4 Answers4

4

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

AppCompat is a library project with resources. You need to reference AppCompat in your Android project.

You could also check this a similar one i answered before. Found it now

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

You can follow the steps @ Adding libraries with resources in the below link

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

Donwload the support library from sdk manager

enter image description here

Import library project to workspace. Can be found @

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

After importing

enter image description here

Right click on your Android Project. Goto Properties. Choose Android. Click Add and choose AppCompact. Click OK. You should see a green tick upon success.

After Referencing

enter image description here

You are done.

Community
  • 1
  • 1
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • I followed the instructions from your link, I'm pretty sure I imported the lib the right way, and Eclipse IDE detects no error. But it crashes when I run the app – Hendra Anggrian Mar 27 '14 at 11:39
  • @Anggrian it can't be that you followed all steps and still end up in errors. You have not followed it properly. and use `@` to address the specific user in your comment – Raghunandan Mar 27 '14 at 12:17
  • @Anggrian pls check the snaps shots. If you do it right it will 100% no doubt about that – Raghunandan Mar 27 '14 at 12:22
  • as I said earlier, I already followed the instruction from your link which I think is the same as the instructions you kindly give via screenshots. But I got this error I cannot build the project or run the app: http://imgur.com/M4xe6J9 – Hendra Anggrian Mar 27 '14 at 12:35
  • @Anggrian no you won't get the errors. Copy the appcompat from `sdk>/extras/android/support/v7/appcompat/` to your folder where androdi project is. Then import into eclipse and then reference the same. – Raghunandan Mar 27 '14 at 12:37
  • @Anggrian do mention the steps that you followed and snap shots in your post not as a link – Raghunandan Mar 27 '14 at 12:38
  • did copy the appcompat folder in my android app project, error still remains – Hendra Anggrian Mar 27 '14 at 12:40
  • you know I did use @ several times but they don't appear here, so my apologies – Hendra Anggrian Mar 27 '14 at 12:41
  • @Anggrian again stressing the point that if you follow all steps it will work 100%%%%. You are missing something. I linked you to docs . posted snap shots that should be enough to fix it – Raghunandan Mar 27 '14 at 12:41
  • you know my head is full of sh1t right now I will go and have a smoke. Will be back to follow your instructions from the scratch and let you know how it goes. Again, thanks. – Hendra Anggrian Mar 27 '14 at 12:43
  • after carefully following your instructions one by one, I still get this error: Description Resource Path Location Type The container 'Android Dependencies' references non existing library 'C:\Program Files\Android Developer Tools\sdk\extras\android\support\v7\appcompat\bin\android-support-v7-appcompat.jar' Readee Build path Build Path Problem @Raghunandan – Hendra Anggrian Mar 28 '14 at 05:19
  • @Anggrian non exisiting. I suggest you check whether the support library is downloaded. remove all the previous references and remove all the tries and try again. Good luck. – Raghunandan Mar 28 '14 at 05:25
  • should I also remove the v4 lib that is included in my app project by default? @Raghunandan – Hendra Anggrian Mar 28 '14 at 05:27
  • @Anggrian no need to remove `android-support-v4.jar` even if removed can be copied from the `sdk/extras/android/support/v4/android-support-v4.jar` under the sdk to the libs folder of both library project and the androd project – Raghunandan Mar 28 '14 at 05:30
  • I did import the lib v7 and now I get a new error: Description Resource Path Location Type error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.AppCompat.Light'. styles.xml /Readee/res/values line 23 Android AAPT Problem @Raghunandan – Hendra Anggrian Mar 28 '14 at 07:30
  • @Anggrian right click on your Appcompat library goto properties goto Android check the latest android api and click ok – Raghunandan Mar 28 '14 at 07:33
  • it's already ticked to the latest and only one I got: 4.4.2 @Raghunandan – Hendra Anggrian Mar 28 '14 at 07:35
  • @Anggrian can you post styles.xml in `/Readee/res/values` – Raghunandan Mar 28 '14 at 07:37
0

enter image description hereAdd suppor library jar using the Java Build Path

0

In Eclipse: File->Import->Existing Android Code into Workspace-> Next. Go to Browse and locate the project "C:\Program Files\Android Developer Tools\sdk\extras\android\support\v7" (in your case) and import it. Then right click on your project -> Properties. Go to Android section on top left. In the bottom window called "Library" click Add and choose the support project you've just imported.

Make sure you import the ActionBar from import android.support.v7.app.ActionBarActivity and not from the import android.app.ActionBar.

taxo
  • 539
  • 1
  • 3
  • 21
0

I had the same problem and tried whole bunch of things (themes, importing external appcompat jars etc).
The only one helped to me:
1) manually copy android-support-v4.jar and android-support-v7-appcompat.jar to the lib folder of the project;
2) right click on the project -> Properties -> Libraries -> Add JARs (not external jars) - > select jars from the lib folder (which we copied on step 1) -> Order and Export tap -> Uncheck old support libraries and check new, which we just added. -> OK.