0

I'm getting an ArithmeticException (Divide by 0) on a few devices in my activity. This is the Stack trace I'm getting

java.lang.ArithmeticException: divide by zero
    at com.afre.quirky.GameActivity.a(Unknown Source)
    at com.afre.quirky.GameActivity.a(Unknown Source)
    at com.afre.f.a.<init>(Unknown Source)
    at com.afre.quirky.d.c(Unknown Source)
    at com.afre.quirky.d.<init>(Unknown Source)
    at com.afre.quirky.a.onClick(Unknown Source)
    at android.view.View.performClick(View.java:4107)
    at android.view.View$PerformClick.run(View.java:17166)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:155)
    at android.app.ActivityThread.main(ActivityThread.java:5559)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1074)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:841)
    at dalvik.system.NativeStart.main(Native Method)

My package name is com.afre.quirky and the activity in which I'm getting the error is GameActivity

And the weird thing is that I'm getting this error on a very few devices (HTC Desire 700 is the one) and also, the stack trace isn't showing the exact line in GameActivity in which I'm getting the error. In addition to that, I don't have any division task in that activity where divisor could be zero.

Here is my GameActivity code

public class GameActivity extends AppCompatActivity {
    private GameView gameView;

    public static int SCREEN_HEIGHT;
    public static int SCREEN_WIDTH;

    ImageView image;
    ImageView demo;
    ImageView loading;
    TextView loadText;

    RelativeLayout mLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_game);

        mLayout = (RelativeLayout) findViewById(R.id.gameLayout);
        image = (ImageView) findViewById(R.id.color);
        demo = (ImageView) findViewById(R.id.demo);
        loading = (ImageView) findViewById(R.id.loading);
        loadText = (TextView) findViewById(R.id.loadText);

        setWidthAndHeight();
    }

    void setWidthAndHeight() {

        Display display = getWindowManager().getDefaultDisplay();
        DisplayMetrics size = new DisplayMetrics();

        int navBarHeight = 0;
        Resources resources = getResources();
        int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0) {
            navBarHeight = resources.getDimensionPixelSize(resourceId);
        }

        boolean hasPhysicalHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);

        if(Build.VERSION.SDK_INT >= 17) {
            display.getRealMetrics(size);
            SCREEN_WIDTH = size.widthPixels;
            SCREEN_HEIGHT = size.heightPixels;
        }
        else if(hasPhysicalHomeKey) {
            SCREEN_WIDTH = new DisplayMetrics().widthPixels;
            SCREEN_HEIGHT = new DisplayMetrics().heightPixels;
        }
        else {
            SCREEN_WIDTH = new DisplayMetrics().widthPixels;
            SCREEN_HEIGHT = new DisplayMetrics().heightPixels + navBarHeight;
        }
    }
}

styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="FullscreenTheme" parent="AppTheme">
        <item name="android:actionBarStyle">@style/FullscreenActionBarStyle</item>
        <item name="android:windowActionBarOverlay">true</item>
        <item name="android:windowBackground">@null</item>
        <item name="metaButtonBarStyle">?android:attr/buttonBarStyle</item>
        <item name="metaButtonBarButtonStyle">?android:attr/buttonBarButtonStyle</item>
    </style>

    <style name="FullscreenActionBarStyle" parent="Widget.AppCompat.ActionBar">
        <item name="android:background">@color/black_overlay</item>
    </style>

    <style name="AppTheme.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="windowNoTitle">true</item>
    </style>

    <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>
Vishal Afre
  • 1,013
  • 3
  • 12
  • 39

0 Answers0