Error inflating class com.actionbarsherlock.internal.widget.ActionBarView

2,209 views
Skip to first unread message

daniel

unread,
Nov 23, 2011, 1:29:06 PM11/23/11
to ActionBarSherlock
When I try to run the integration tests, every activity that has an
ActionBar crash with nullpointer i logcat.
What could this be? The application is working perfectly when started
manualy from the emulator.

Caused by: android.view.InflateException: Binary XML file line #33:
Error inflating class
com.actionbarsherlock.internal.widget.ActionBarView
at android.view.LayoutInflater.createView(LayoutInflater.java:
518)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:
623)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:
626)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:
207)
at android.app.Activity.setContentView(Activity.java:1657)
at
android.support.v4.app.FragmentActivity.ensureSupportActionBarAttached(FragmentActivity.java:
219)
at
android.support.v4.app.FragmentActivity.setContentView(FragmentActivity.java:
290)
at net.mythird.ui.notes.NoteActivity.onCreate(NoteActivity.java:
19)
at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
1611)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:
415)
at android.view.LayoutInflater.createView(LayoutInflater.java:
505)
... 24 more
Caused by: java.lang.NullPointerException
at
com.actionbarsherlock.internal.widget.ActionBarView.<init>(ActionBarView.java:
136)
at
com.actionbarsherlock.internal.widget.ActionBarView.<init>(ActionBarView.java:
100)
... 27 more

daniel

unread,
Nov 24, 2011, 4:38:53 PM11/24/11
to ActionBarSherlock
I have done some debugging, using eclipse debugger and digging around
the view instance hierarchy.

When launching manually in the emulator the actionbar looks exactly
like its design in layout/abs__action_bar.xml
All the values is from the debugger where I set a breakpoint at the
start of the "public ActionBarView(final Context context, AttributeSet
attrs, int defStyle)" method.

ActionBarView
- LinearLayout (ID: -1)
- RelativeLayout (ID, -1, NinePatch, actionbar_background.9.png)
- LinearLayout (ID: 2131099657) (R.id.abs__home_wrapper)
LinearLayout (ID: -1)
- ImageView (ID: 2131099663) (R.id.abs__up)
- ImageView (ID: 2131099664) (R.id.abs__home)

- LinearLayout (ID: 2131099658) (R.id.abs__actions)
- RelativeLayout (ID: -1)
- ProgressBar (ID: 2131099659) (R.id.abs__iprogress)
- FrameLayout (ID: -1)
- LinearLayout (ID: -1)
- ScrollingTextView (ID: 2131099672) (R.id.abs__action_bar_title)
- ScrollingTextView (ID: 2131099673)
(R.id.abs__action_bar_subtitle)
- Spinner (ID: 2131099660) (R.id.abs__nav_list)
- FrameLayout (ID: 2131099661) (R.id.abs__custom)

- LinearLayout (ID:2131099662,
NinePatch;abs__ab_stacked_transparent_light_holo.9.png)
(R.id.abs__nav_tabs)

At line 136 it asks for the view R.id.abs__action_bar_title.
Debugger says "R.id.abs__action_bar_title" is 2131099672
From what I see above, that is the ScrollingTextView
(R.id.abs__action_bar_title)

----------------------------------------------------------------------------------------------------------------------

When running as instrumentation test:
ActionBarView
LinearLayout (id: -1)
RelativeLayout (ID, -1, NinePatch, actionbar_background.9.png)
LinearLayout (ID: 2131099657) (R.id.abs__home_wrapper)
LinearLayout (ID: 2131099658) (R.id.abs__actions)
RelativeLayout (ID: -1)
ProgressBar (ID: 2131099659) (R.id.abs__iprogress)
FrameLayout (ID: -1)
LinearLayout (ID: -1)
ScrollingTextView (ID: 2131099672) (R.id.abs__action_bar_title)
ScrollingTextView (ID: 2131099673)
(R.id.abs__action_bar_subtitle)

Spinner (ID: 2131099660) (R.id.abs__nav_list)
FrameLayout (ID: 2131099661) (R.id.abs__custom)

LinearLayout (ID: 2131099662) (R.id.abs__nav_tabs)
(abs__ab_stacked_transparent_light_holo.9.png)


At line 136 it asks for the view R.id.abs__action_bar_title.
Debugger says "R.id.abs__action_bar_title" is 2130968600

... there is no view 2130968600.
... why has "R.id.abs__action_bar_title" that value at all? (only when
running instrumentationtests...) when running normaly, the id points
to a valid view. .

daniel

unread,
Nov 25, 2011, 8:16:09 AM11/25/11
to ActionBarSherlock
seems that for some reason the ids in my integrationtest R.java file
is different from those in the application R.java file.


ids from the application R.java:
public static final int abs__action_bar=0x7f06001b;
public static final int abs__action_bar_container=0x7f06001a;
public static final int abs__action_bar_subtitle=0x7f060019;
public static final int abs__action_bar_title=0x7f060018;

ids from the integrationtests R.java:
public static final int abs__action_bar=0x7f04001b;
public static final int abs__action_bar_container=0x7f04001a;
public static final int abs__action_bar_subtitle=0x7f040019;
public static final int abs__action_bar_title=0x7f040018;

Why just the two 60 and 40 and all the other characters are the same?
Have to read up about how those ids are formed.

daniel

unread,
Nov 25, 2011, 8:44:39 AM11/25/11
to ActionBarSherlock
Heh, seems like its the genereated R.java file in the integration
tests project that are used on the classpath when running
instrumentation tests, they contains the merged result of all ids in
the project, including those frome the actionbar library.
If this is right or not, sound to me like it should use the original
one from the application R.java instead, but thats another question.

From what it looks like, its pure by coincidence if the IDS from the
original app match with the one generated in the tests project.
I removed an unsued anim folder from the application project, and that
dropped the generated values of all ids from 0x7f060xxxx; to
0x7f050xxxx;
Then I added a bogus xml folder into the test project, and put a
bogus.xml into that folder, which bumped the generated ids values in
the test project from 0x7f040xxxx; to 0x7f050xxxx;

So for now, the ids in the test and application project has been
aligned again :)
and all my tests are back running...

Jake Wharton

unread,
Nov 25, 2011, 11:52:45 AM11/25/11
to actionba...@googlegroups.com
Are you running these tests through maven or launching through an IDE?

---
Jake Wharton
http://about.me/jakewharton

daniel

unread,
Nov 26, 2011, 6:58:07 AM11/26/11
to ActionBarSherlock
maven

On 25 Nov, 17:52, Jake Wharton <jakewhar...@gmail.com> wrote:
> Are you running these tests through maven or launching through an IDE?
>
> ---

> Jake Whartonhttp://about.me/jakewharton

Jake Wharton

unread,
Nov 26, 2011, 4:46:12 PM11/26/11
to actionba...@googlegroups.com

You may want to ask on the maven android Google Group as Manfred knows just about everything there is about how the android plugin works. He'll be able to tell you exactly what's going on and whether or not it's a bug.

---
Jake Wharton
http://about.me/jakewharton

Roberto Tyley

unread,
Dec 6, 2011, 9:09:28 AM12/6/11
to actionba...@googlegroups.com
I'm using the android-maven-plugin (3.0.0-alpha-14) and seeing similar problems in my integration tests - there are some different ids in both the R.java files for actionbarsherlock and also the main project package.

I'm guessing that Jake is right and this is in some way a problem with the android-maven-plugin - it's probably passing the wrong source files to aapt and generating the wrong ids... or maybe it shouldn't be using those R files at all - the whole area is a bit arcane to me. Daniel, did you get any further with analysing the issue or have you been getting by with your workaround of creating matching xml folders in your integration test project?

Roberto 

Jake Wharton

unread,
Dec 8, 2011, 11:34:52 PM12/8/11
to actionba...@googlegroups.com
If someone could create a small test case app that exhibits this I can work with Manfred in seeing about getting the bug the maven plugin resolved. I haven't seen this in any of my small apps unfortunately.

daniel

unread,
Dec 9, 2011, 4:02:21 AM12/9/11
to ActionBarSherlock


On 6 Des, 15:09, Roberto Tyley <roberto.ty...@gmail.com> wrote:
> I'm using the android-maven-plugin (3.0.0-alpha-14) and seeing similar
> problems in my integration tests - there are some different ids in both the
> R.java files for actionbarsherlock and also the main project package.
>
> I'm guessing that Jake is right and this is in some way a problem with
> the android-maven-plugin - it's probably passing the wrong source files to

> aapt<http://developer.android.com/guide/developing/building/index.html#det...> and


> generating the wrong ids... or maybe it shouldn't be using those R files at
> all - the whole area is a bit arcane to me. Daniel, did you get any further
> with analysing the issue or have you been getting by with your workaround
> of creating matching xml folders in your integration test project?

Im using my workaround for the time. Have had no trouble with the
workaround solution.

>
> Roberto

daniel

unread,
Dec 9, 2011, 4:23:04 AM12/9/11
to ActionBarSherlock

On 6 Des, 15:09, Roberto Tyley <roberto.ty...@gmail.com> wrote:
> I'm using the android-maven-plugin (3.0.0-alpha-14) and seeing similar
> problems in my integration tests - there are some different ids in both the
> R.java files for actionbarsherlock and also the main project package.
>
> I'm guessing that Jake is right and this is in some way a problem with
> the android-maven-plugin - it's probably passing the wrong source files to
> aapt<http://developer.android.com/guide/developing/building/index.html#det...> and

> generating the wrong ids... or maybe it shouldn't be using those R files at
> all - the whole area is a bit arcane to me. Daniel, did you get any further
> with analysing the issue or have you been getting by with your workaround
> of creating matching xml folders in your integration test project?

When generating sources in integration tests project,the generated R
file contains all IDS, combined from all apklibs and dependent apks.
This R file is used by the application when running the tests.The
trouble is that this R file is not the same, and may not contain the
same IDS as the application under test.
This is because the generated R file in the integration tests also
contain IDS from resource from the the integration tests res folder,
which may have a different structure and therefor different ids.

Thats my theory, and its the android-maven-plugin that generates the R
file.
Its a bit strange, because the res folder of the integration tests
most likely never match the main application res folder in structure.
You dont put very much into the res folder of the integration tests at
all, and you would think this would be a very common problem when
using others apklibs.

Roberto Tyley

unread,
Dec 9, 2011, 10:22:21 AM12/9/11
to actionba...@googlegroups.com
I modified the 'library' sub-project in maven-android-plugin-samples, adding ActionBarSherlock, to see if I could reproduce the problem there... however, all the integration tests passed without any problem:


Adding additional resource folders, to disturb the generated IDs in the R.java files, didn't seem to cause the project to fail either, which was contrary to what I was expecting given daniel's workaround.


However, I did notice that in the sample project, the integration test module includes the implementation artifact using the 'provided' scope (twice, once for the apk to be installed, and again to compile against):


I hadn't been using the 'provided' scope in my project, and I think this may be a factor in the problem. Perhaps critical ids are being reassigned new values because they're being included for a second time in the integration test apk?

I've tried to demonstrate this by setting 'provided' scope on various projects, but unfortunately with varying degrees of success. Give it a try, see if it works for you - on the projects I've tried where it's failed, I think the failures may be due to unassociated bugs that I had just hitherto failed to encounter because of this issue...!

Roberto


daniel

unread,
Dec 9, 2011, 1:29:24 PM12/9/11
to ActionBarSherlock
I have made a test case for the issue: http://dl.dropbox.com/u/4723421/actionbartestcase.zip
Its just a clean created project from the android maven archetype,
with added actionbarsherlock and some new resource folders.
Building it straight away would fail with the mention error message.
To solve this, add <scope>provided</scope> as directed in the
application-it/pom.xml

As a bonus, android-maven-plugin 3.0.0 will not compile this project
before <scope>provided</scope> are set for both dependencies in
application-it/pom.xml
I set android-maven-plugin to 3.0.0-alpha-14 just to be able to show
the error message when running tests, 3.0.0 will crash even earlier
without provided-scope.

Daniel

On 9 Des, 16:22, Roberto Tyley <roberto.ty...@gmail.com> wrote:
> I modified the 'library' sub-project in maven-android-plugin-samples,
> adding ActionBarSherlock, to see if I could reproduce the problem there...
> however, all the integration tests passed without any problem:
>

> https://github.com/rtyley/maven-android-plugin-samples/commits/action...


>
> Adding additional resource folders, to disturb the generated IDs in the
> R.java files, didn't seem to cause the project to fail either, which was
> contrary to what I was expecting given daniel's workaround.
>
> However, I did notice that in the sample project, the integration test
> module includes the implementation artifact using the 'provided' scope
> (twice, once for the apk to be installed, and again to compile against):
>

> https://github.com/rtyley/maven-android-plugin-samples/blob/actionbar...


>
> I hadn't been using the 'provided' scope in my project, and I think this
> may be a factor in the problem. Perhaps critical ids are being reassigned
> new values because they're being included for a second time in the
> integration test apk?
>
> I've tried to demonstrate this by setting 'provided' scope on various
> projects, but unfortunately with varying degrees of success. Give it a try,
> see if it works for you - on the projects I've tried where it's failed, I
> think the failures may be due to unassociated bugs that I had just hitherto

> failed to encounter because of *this* issue...!
>
> Roberto

Jake Wharton

unread,
Dec 12, 2011, 2:07:58 PM12/12/11
to actionba...@googlegroups.com

Sebastian Harder

unread,
Apr 12, 2012, 11:29:27 AM4/12/12
to actionba...@googlegroups.com
I am experiencing a similar problem, except that it has nothing to do with a test project.

I have a little project to play around with ABS, really simple with one activity, an actionbar, some tabs and everything works.
However when I add an anim folder from another project, namely https://github.com/lorensiuswlt/NewQuickAction3D, the app crashes immediatelly with the following log:

04-12 17:15:34.167: E/AndroidRuntime(6401): FATAL EXCEPTION: main
04-12 17:15:34.167: E/AndroidRuntime(6401): java.lang.RuntimeException: Unable to start activity ComponentInfo{tv.px.android.play/tv.px.android.play.Android4TestsActivity}: android.view.InflateException: Binary XML file line #31: Error inflating class com.actionbarsherlock.internal.widget.ActionBarView
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1768)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.app.ActivityThread.access$1500(ActivityThread.java:123)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.os.Looper.loop(Looper.java:130)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.app.ActivityThread.main(ActivityThread.java:3835)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at java.lang.reflect.Method.invokeNative(Native Method)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at java.lang.reflect.Method.invoke(Method.java:507)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:864)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at dalvik.system.NativeStart.main(Native Method)
04-12 17:15:34.167: E/AndroidRuntime(6401): Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class com.actionbarsherlock.internal.widget.ActionBarView
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(ActionBarSherlockCompat.java:1033)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:903)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:837)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:212)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at tv.px.android.play.Android4TestsActivity.onCreate(Android4TestsActivity.java:54)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
04-12 17:15:34.167: E/AndroidRuntime(6401):     ... 11 more
04-12 17:15:34.167: E/AndroidRuntime(6401): Caused by: java.lang.reflect.InvocationTargetException
04-12 17:15:34.167: E/AndroidRuntime(6401):     at java.lang.reflect.Constructor.constructNative(Native Method)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)
04-12 17:15:34.167: E/AndroidRuntime(6401):     ... 24 more
04-12 17:15:34.167: E/AndroidRuntime(6401): Caused by: java.lang.NullPointerException
04-12 17:15:34.167: E/AndroidRuntime(6401):     at com.actionbarsherlock.internal.widget.ActionBarView$HomeView.setUp(ActionBarView.java:1302)
04-12 17:15:34.167: E/AndroidRuntime(6401):     at com.actionbarsherlock.internal.widget.ActionBarView.<init>(ActionBarView.java:235)
04-12 17:15:34.167: E/AndroidRuntime(6401):     ... 27 more

As soon as I delete all the xml files from this anim folder everything works normally.

Using maven, android-maven-plugin and ABS 4.0.1.

schwiz

unread,
Jul 3, 2012, 2:55:56 PM7/3/12
to actionba...@googlegroups.com
Deleting your animation resources doesn't seem like a real solution. Did you ever find a fix?

Andrea Richiardi

unread,
Jan 9, 2014, 2:27:39 AM1/9/14
to actionba...@googlegroups.com
Not a solution, but this might happen while compiling the main app as well.

See: http://stackoverflow.com/questions/21008515/npe-while-inflating-actionbarsherlock-on-old-androids

I am using the latest 1.5 Snapshot of m2e and aapt from 19.0.1 build tools.


On Wednesday, 23 November 2011 10:29:06 UTC-8, daniel wrote:
When I try to run the integration tests, every activity that has an
ActionBar crash with nullpointer i logcat.
What could this be? The application is working perfectly when started
manualy from the emulator.

[CUT]

Andrea Richiardi

unread,
Jan 9, 2014, 1:38:12 PM1/9/14
to actionba...@googlegroups.com
I did this in my project. Debugging more on :)

- I checked where ActionBarSherlock was failing, for me it was while loading the resource R.id.abs__up.
- I have got the resource number from an Eclipse and take the prefix (0x7f07XXXX);
- I went in my compiled R.java and removed all the resources before 0x7f07XXXX, cleaned the project. This way I wanted to align R.id.abs__up to its real number (0x7f04000b). I had to remove three folders, for testing.
- Now R.id.abs__up had the correct number in my compiled R.java.

Launch the app (after fixing compiling errors) and boom, same problem, this time R.id.abs__action_bar_title is not aligned with the apklib R file.

I am not an expert of this so I might be saying something very stupid here, but I was wondering...if the R file is wrongly generated by aapt...why don't we add an extra, post-processing step in the maven-android-plugin (or somewhere else) to modify our ids back to match the ids of imported apklibs?





On Wednesday, 23 November 2011 10:29:06 UTC-8, daniel wrote:
When I try to run the integration tests, every activity that has an
ActionBar crash with nullpointer i logcat.
What could this be? The application is working perfectly when started
manualy from the emulator.

Caused by: android.view.InflateException: Binary XML file line #33:
Error inflating class
com.actionbarsherlock.internal.widget.ActionBarView
       at android.view.LayoutInflater.createView(LayoutInflater.java:

[CUT]

Andrea Richiardi

unread,
Jan 9, 2014, 4:13:29 PM1/9/14
to actionba...@googlegroups.com
I had to remove other three resources id declare like this:

  <item type="id" name="empty_conf_id"/>
  <item type="id" name="vibro_conf_id"/>
  <item type="id" name="ring_conf_id"/>
    
And now the resources are aligned again! And it works for API 8 & API 11 again.
About the anim/ folder. If you add it back again, it messes things up, so I had to put my animations in drawable/ for now.
Reply all
Reply to author
Forward
0 new messages