I solved the problem, but it isn't most pretty solution.
I check for the size of the action bar. If it exist, I run the code shown in the question. If the size returns null, which means that the action bar doesn't exist, I don't run the code.
The code is:
// Check if an action bar exist (Android 4.XX)
private void getActionBarHeight() {
// TODO Auto-generated method stub
final WindowManager w = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
final Display d = w.getDefaultDisplay();
final DisplayMetrics m = new DisplayMetrics();
d.getMetrics(m);
actionBarHeight = m.heightPixels;
try { // If the action bar exist
TypedValue tv = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
getResources().getDimensionPixelSize(tv.resourceId);
} catch (Exception e) { // If it doesn't exist
actionBarHeight = -1;
}
}