I am trying to get the screen size on my emulator (API 7) with this code:
float scaledDensity = this.getResources().getDisplayMetrics().scaledDensity;
Now I try to use scaledDensity
with this code:
int width = (width / ((int) scaledDensity)) / 7;
and I get this exception
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tomer.workoutlog2/com.example.workoutlog.SimpleCalendarViewActivity}: java.lang.ArithmeticException: divide by zero
Full code:
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE))
.getDefaultDisplay();
int width = 0;
if (android.os.Build.VERSION.SDK_INT >= 13) {
Point size = new Point();
display.getSize(size);
width = size.x;
} else
width = display.getWidth();
float scaledDensity = this.getResources().getDisplayMetrics().scaledDensity;
width = (width / ((int) scaledDensity)) / 7;
On my real device I don't get this error. Maybe, is the problem with the emulator?