Tag: Code

MenuInflater NullPointerException (NPE)

I just recently published my first app on Google Play, and after I had published it I was playing with it on my Galaxy S3 and it crashed when I tried to delete a page. I know I had this working correctly on my Nexus 7 prior to publishing it, but I didn’t test it on my phone (shame on me :(). So, I went to work trying to figure out what the problem was, and here’s part of the stack trace:

FATAL EXCEPTION: main
java.lang.NullPointerException
	at com.actionbarsherlock.view.MenuInflater.inflate(MenuInflater.java:109)
	at com.test.app.SomeFragment.onCreateOptionsMenu(SomeFragment.java:1921)
	at android.support.v4.app.Watson.onCreatePanelMenu(Watson.java:55)
	at com.actionbarsherlock.ActionBarSherlock.callbackCreateOptionsMenu(ActionBarSherlock.java:559)
	at com.actionbarsherlock.internal.ActionBarSherlockNative.dispatchCreateOptionsMenu(ActionBarSherlockNative.java:65)
	at com.actionbarsherlock.app.SherlockFragmentActivity.onCreatePanelMenu(SherlockFragmentActivity.java:165)
	at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:446)
	at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:820)
Read more...

Android Tutorial: Implement A Shake Listener

So I’ve been playing around with Android and have a little app that I wanted the user to be able to shake the phone and have something happen. I did some digging and the following is a tutorial on how to setup a shake listener to capture a shake and then do whatever you want.

This is by no means something that I’ve created, I just used examples that I found on stackoverflow.com. Also, this uses G-force to calculate the shake threshold. Many thanks to Peterdk and Akos Cz for their input and answer for this solution. Peterdk recommended using the G-Force app by Blake La Pierre on Google Play Store if you want to get the actual G-force value on your phone and tweak it in the code below.… Read more...