AnswerBun.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!

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 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir