I got my 1st crash report for my app. It says there is a java.lang.ArithmeticException: divide by zero
The exception is on one of these two lines:
//sWP stands for "Screen Width in Pixels"
// sW stands for "Screen Width" The code is old though, so I may be incorrect for both variables.
//res is just getResources()
int sWP = sW / (res.getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
float bHeight = 50 * ((float)res.getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
Can DisplayMetrics.DENSITY_DEFAULT ever be zero? Or can getDisplayMetrics().densityDpi ever be zero?
res.getDisplayMetrics().densityDpiwill be 120, 160 or 240 (or something similar), see https://developer.android.com/reference/android/util/DisplayMetrics.html#densityDpi.DisplayMetrics.DENSITY_DEFAULTconstantly equals 160, see https://developer.android.com/reference/android/util/DisplayMetrics.html#DENSITY_DEFAULT.res.getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULTwill return 0 because you divide int by int.Change the first of the two lines to
int sWP = (int) sW / (((double) res.getDisplayMetrics().densityDpi) / DisplayMetrics.DENSITY_DEFAULT);and it should work.