• Post Reply Bookmark Topic Watch Topic
  • New Topic

Moving back an element in an array  RSS feed

 
Brian Barrick
Ranch Hand
Posts: 67
Android Java
  • Mark post as helpful
  • send pies
  • 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

 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • 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.
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • 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: 67
Android Java
  • Mark post as helpful
  • send pies
  • 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: 67
Android Java
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!