• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Moving back an element in an array

 
Ranch Hand
Posts: 73
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I posted this in the Android sub forum but it doesn't seem to get near as much activity so I thought since it was still Java maybe it would be alright to ask here as well...

Can anyone give me a clue as to why the following code doesn't work? Getting the next element works but getting the previous doesn't. I'm not sure I understand why the next works because the % returns the remainder of the index divided by the array length correct? With the previous code I even tried using mQuestionBank.length but it still crashes when I click the button. I haven't figured where I can look at the exact errors I'm getting in Android Studio yet either which doesn't help.

Thanks

 
Marshal
Posts: 72904
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Brian Barrick wrote: . . . maybe it would be alright to ask here as well...
. . .

No, it isn't all right. I have deleted the other version of your question.

We shall require more details of what happens before we can help. And Android is not plain simple Java®.
Yes, the % operator returns the remainder when you divide; you can use it to rotate an array, but it won't work at all well if the left operand is negative.
 
Sheriff
Posts: 7111
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My only thought is, is mCurrentIndex supposed to be 1 through 5 or 0 through 4?

What is you Android environment? Maybe someone can help you see your errors.
 
Brian Barrick
Ranch Hand
Posts: 73
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, well then just go ahead and delete this thread as well then. I'm sure I can find an android forum that is a little more active. I don't want to bother anyone with something on a Java thread that isn't Java.
 
Brian Barrick
Ranch Hand
Posts: 73
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:My only thought is, is mCurrentIndex supposed to be 1 through 5 or 0 through 4?

What is you Android environment? Maybe someone can help you see your errors.



Android Studio, changing it to 4 it works so I guess that's what it was although I would have thought mCurrentIndex.length would have been the same thing.

I appreciate your help.
 
What a show! What atmosphere! What fun! What a tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic