TransWikia.com

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(SliderLayout.java:664)
   2. at com.daimajia.slider.library.SliderLayout.setCurrentPosition(SliderLayout.java:670)
    3.at com.example.testapp.MainActivity.onCreate(MainActivity.java:53)**
  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);
    }
2.

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




3. 

mainSlider = (SliderLayout) findViewById(R.id.main_slider);
        setSlider();
        PagerIndicator pagerIndicator = (PagerIndicator) findViewById(R.id.custom_indicator);
        mainSlider.setCustomIndicator(pagerIndicator);
        mainSlider.setDuration(3);
        **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) {
     e.printStackTrace();
  }

Answered by afhamu on August 28, 2020

Add your own answers!

Ask a Question

Get help from others!

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