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!

Related Questions

Can not put a T in Map

1  Asked on November 25, 2020 by hemant


If and excel formula for matching

1  Asked on November 23, 2020 by howaboutno


Pyspark Transpose

1  Asked on November 23, 2020 by sawan-s


How to aggregate data, pass and fail as final result?

1  Asked on November 23, 2020 by user584018


Comparing two lists for same value

1  Asked on November 22, 2020 by sebaku


Crystal Reports won’t display related table data

2  Asked on November 22, 2020 by rharris


Upgrading spring cloud version from Edgware to Hoxton

3  Asked on November 21, 2020 by ruchira-gayan-ranaweera


How to prevent button form Angular?

5  Asked on November 20, 2020 by user13976004


SQL union seems to fail for me

1  Asked on November 19, 2020 by sasha-peric


My Projectiles Stop Shooting Problem How To Fix?

1  Asked on November 19, 2020 by habib-ismail


Ask a Question

Get help from others!

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