Cannot Resolve @style/Theme.Sherlock

2020-02-25 06:23发布

I'm trying to make use of Actionbar Sherlock 4, targeting sdk 15 and min sdk 8. After following the directions provided on the Usage website and the great videos posted here: http://www.youtube.com/watch?v=avcp6eD_X2k

I'm still encountering a problem. When I try to add android:theme="@style/Theme.Sherlock" to my manifest file , I get the error:

No resource found that matches the given name (at 'theme' with value '@style/Theme.Sherlock').

I have included the actionbar Sherlock library project into my project, and the import statements are there and not coming up with any errors and I've

extends SherlockActivity implements ActionBar.TabListener

just like in the Demo code and documentation Yet still, eclipse gives me this error. Any ideas out there?

6条回答
forever°为你锁心
2楼-- · 2020-02-25 06:51

The pitfall I encountered was this: The reference to the ActionBarSherlock project needs to be in the Android->Libraries section of the project properties, while I had been adding it to the Build Path->Libraries.

查看更多
爷、活的狠高调
3楼-- · 2020-02-25 06:59

My standard procedure for including a library project on Eclipse goes like this:

  • Import library project
  • Right click on library project Properties -> Android -> Set Project Build Target (insure library and primary project are the same)
  • Right click on library project Android Tools -> Fix Project Properties
  • Select the library project then Project -> Clean...
  • Select primary project then Project -> Clean...

That should fix whatever ails you.

查看更多
Bombasti
4楼-- · 2020-02-25 07:05

I finally find the solution:

  1. IMPORTANT! Copy the same android-support-v4.jar in both projects: in library and your project (this is the principal problem).
  2. Import "library" project TO YOUR WORKSPACE
  3. Right click on library project Properties -> Android -> Check "Target Name" 4.x (any, API level 14,15 or 16). Bottom check "Is library".
  4. In properties, go to "Java Build Path", tab "Libraries" And find "android-support-v4.jar" normally in "Android Dependencies". Ok and Close Properties.
  5. Right click on library project Android Tools -> Fix Project Properties
  6. in Menu Project -> Clean... and select to clean the "Library" Project.

In this place, your project "library" must to be done (without errors)

  1. Create or import your own project. Example "MyProject"
  2. In properties, go to "Java Build Path", tab "Libraries" And find "android-support-v4.jar" normally in "Android Dependencies".
  3. Now go to "Projects" Tab. Add... and select "library" project.
  4. Now in properties go to Android -> Check "Target Name" 4.x (any, API level 14,15 or 16). IMPORTANT: Must to be the same of "library" project. Bottom "Is Library" must to be UNCHECKED and in this place press Add... And select "library" project. Ok and Close properties.
  5. Right click on "MyProject" project Android Tools -> Fix Project Properties
  6. in Menu Project -> Clean... and select to clean the "MyProject" Project.

Already, your project must to be done. If the error persist, restart Eclipse.

查看更多
爷、活的狠高调
5楼-- · 2020-02-25 07:05

after importing both projects i.e. library and settingActivity,first clean and build them. Then right click on settingActivity project->properties->select second option from left menu (i.e android). on right hand side their is library section just click on add library. prper path will automatically comes in that frame. Thats solve my problem,i got no errors.

查看更多
Rolldiameter
6楼-- · 2020-02-25 07:10

I resolved this issue by the follwoing 2 steps on my projects:

  1. Remove the "library" from "project properties"/build path and add library in "project properties"/Android/Library
  2. Right Click on project "Android Tools" -> "Add support library"
查看更多
▲ chillily
7楼-- · 2020-02-25 07:15

I encountered a strange anomaly that might help!

Have built android project that uses ABS, running it on Gingerbread works fine, in ICS it crashes, the crash under ICS occurs due to this, check your AndroidManifest.xml (have trimmed out bits for brevity...

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" android:theme="@style/Theme.Sherlock">

It was the android:theme part that caused the crash under ICS, it worked fine under Gingerbread and older versions!. Solution was to remove it completely! Then from your Activity, do this:

@Override
public void onCreate(Bundle savedInstanceState) {
   if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH){
        this.setTheme(com.actionbarsherlock.R.style.Theme_Sherlock);
   }
   super.onCreate(savedInstanceState);
   ... // MORE CODE ....
}

This fixed up the crash under ICS, the theme style is not liked by ICS, but it works fine for both versions less than 2.3 and 4.0 upwards.. weird error but that I discovered by fluke!

Remember to apply the theme before calling the base class's own onCreate!

查看更多
登录 后发表回答