Caused by: java.lang.ArithmeticException: divide by zero on Main Activity

Stack Overflow Asked by Loopinfility on August 28, 2020

So i am trying to run an android application on my device, however i am getting the same run time error every time java.lang.ArithmeticException: divide by zero so my application starts and closes immediately.

In the log says that is Caused by: java.lang.ArithmeticException: divide by zero. Accordingly i am going to present you what the code is in those three lines.

 1.**at com.daimajia.slider.library.SliderLayout.setCurrentPosition(
   2. at com.daimajia.slider.library.SliderLayout.setCurrentPosition( com.example.testapp.MainActivity.onCreate(**
  1. public void setCurrentPosition(int position, boolean smooth) {
    if (getRealAdapter() == null)
    throw new IllegalStateException("You did not set a slider adapter");
    if(position >= getRealAdapter().getCount()){
    throw new IllegalStateException("Item position is not exist");
    int p = mViewPager.getCurrentItem() % getRealAdapter().getCount();
    int n = (position – p) + mViewPager.getCurrentItem();
    mViewPager.setCurrentItem(n, smooth);

 public void setCurrentPosition(int position) {
            **setCurrentPosition(position, true);**


mainSlider = (SliderLayout) findViewById(;
        PagerIndicator pagerIndicator = (PagerIndicator) findViewById(;
        **mainSlider.setCurrentPosition(app.heritageSites.size() - 1);**

The lines which have the asterisks are those one’s who have the problem.

One Answer

Try handling the exception:

try {
     mainSlider.setCurrentPosition(app.heritageSites.size() - 1);
  } catch (ArithmeticException e) {

Answered by afhamu on August 28, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP