34

I am new to android-programming. I am following this tutorial to add an ActionBar to my Main_Activity using the explanation in the "Support Android 2.1 and Above" section.

I followed this tutorial to add a Library-Project. Then after adding the library, at the point "Add the library to your application project: I felt lost .. basically because I don't have the "add" option by itself in my Eclipse ..

however I clicked on "add library" and moved on ..

now when I change Activity to ActionBarActivity :

public class MainActivity extends ActionBarActivity { ... }

in my mainActivity.java , it gives me error (a red line bellow the ActionBarActivity and all methods' names and some functions) .. and again when i change:

<activity android:theme="@style/Theme.AppCompat.Light" ... >

in the Manifest, it also give me an error saying: No resource found that matches the given name ..

I am totally lost .. what did I do wrong ?

hashDefine
  • 1,491
  • 6
  • 23
  • 33

10 Answers10

30

Check if you have a android-support-v4.jar file in YOUR project's lib folder, it should be removed!

In the tutorial, when you have followed the instructions of Adding libraries WITHOUT resources before doing the coorect Adding libraries WITH resources you'll get the same error.

(Don't know why someone would do something like that *lookingawayfrommyself* ^^)

So what did fix it in my case, was removing the android-support-v4.jar from YOUR PROJECT (not the android-support-v7-appcompat project), since this caused some kind of library collision (maybe because in the meantime there was a new version of the suport library).

Just another case, when this error might shows up.

Levite
  • 17,263
  • 8
  • 50
  • 50
  • 3
    Strangely this solves it. Good thing am moving to android studio. – RicNjesh Jul 17 '14 at 12:40
  • Note that this error also comes up for me if I have "closed all projects" before creating a new android project. In particular, the appcompat_v7 project must be open, as well as my new project, in order to build the new project. – Colin Oct 21 '14 at 00:35
  • 1
    removing the android-support-v4.jar saved my life. Thank you for the tip – Ayaz Alifov May 27 '15 at 15:43
20

This way work for me with Eclipse in Android developer tool from Google -righ click - property - java build path - add external JAR

point to: android-support-v7-appcompat.jar in /sdk/extras/android/support/v7/appcompat/libs

Then

import android.support.v7.app.ActionBarActivity;
LE SANG
  • 10,955
  • 7
  • 59
  • 78
17

It does not sound like you imported the library right especially when you say at the point Add the library to your application project: I felt lost .. basically because I don't have the "add" option by itself .. however I clicked on "add library" and moved on ..

in eclipse you need to right click on the project, go to Properties, select Android in the list then Add to add the library

follow this tutorial in the docs

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

tyczj
  • 71,600
  • 54
  • 194
  • 296
  • I followed the same tutorial .. but when I open _Properties_, it always opens at _Java build Path_ and then when i go to _Libraries_ I found no add .. yours is more clear and **it is working now** .. **thanks** – hashDefine Sep 16 '13 at 14:54
  • Note that as the "support library" is now deprecated it is not lised by default - there is only the "support repository". You need to check the "show: obsolete" checkbox to see it. – wu-lee May 04 '16 at 16:44
3

I was also following the instructions on http://developer.android.com/training/basics/actionbar/setting-up.html

and even though I did everything in the tutorial, as soon as "extends Action" is changed to "extends ActionBarActivity" all sorts of errors appear in Eclipse, including the "ActionBarActivitycannot be resolved to a type"

None of the above solutions worked for me, but what did work is adding this line to the top:

import android.support.v7.app.ActionBarActivity;

ahetman
  • 1,274
  • 11
  • 17
2

Instead of copy/pasting the code from the tutorial, use the code suggestion in the IDE. Start typing "extends ActionBar..." it will propose "ActionBarActivity" click enter. It worked for me!

Rom Rom
  • 1
  • 1
1

UPDATE:

Since the version 22.1.0, the class ActionBarActivity is deprecated, so instead use AppCompatActivity. For more details see here

Using ActionBarActivity:

In Eclipse:

1 - Make sure library project(appcompat_v7) is open & is proper referenced (added as library) in your application project.

2 - Delete android-support-v4.jar from your project's libs folder(if jar is present).

3 - Appcompat_v7 must have android-support-v4.jar & android-support-v7-appcompat.jar inside it's libs folder. (If jars are not present copy them from /sdk/extras/android/support/v7/appcompat/libs folder of your installed android sdk location)

4- Check whether ActionBarActivity is properly imported.

import android.support.v7.app.ActionBarActivity;

In Android Studio

Just add compile dependencies to app's build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
}
Amrit Pal Singh
  • 7,116
  • 7
  • 40
  • 50
0

Add this line to dependencies in build.gradle:

dependencies {
compile 'com.android.support:appcompat-v7:18.0.+'
}

Reference

Bowdzone
  • 3,827
  • 11
  • 39
  • 52
ufukomer
  • 1,021
  • 1
  • 14
  • 16
0

I got the same problem, but things got complicated when I added few other libraries like appcompat.v7, recyclerView, CardView.

Removing appcompat.v4 from lib did not work for me.

I had to create project from start and first step I did is to remove appcompat.v4 from libs folder, and this worked.

I had just started the project so creating a new project wasn't a big issue for me!!!

Harshil
  • 1,230
  • 17
  • 22
0

There is a mistake in your 'andrroid-sdk' folder. You selected some features while creating new project which need some components to import. It is needed to download a special android library and place it in android-sdk folder. For me it works fine: 1-Create a folder with name extras in your android-sdk folder 2-Create a folder with name android in extras 3-Download this file.(In my case I need this library) 4-Unzip it and copy the content (support folder) in the current android folder 5-close Eclipse and start it again 6-create your project again

I hope it to work for you.

ganji
  • 752
  • 7
  • 17
0

For Eclipse, modify project.properties like this: (your path please)

android.library.reference.1=../../../../workspace/appcompat_v7_22

And remove android-support-v4.jar file in your project's libs folder.

HackNone
  • 504
  • 6
  • 12