-3

I have a method leftup which has an onClick listener from a button. The purpose of method leftup is to do the following:

  1. Get an array from resources xml (Which contains names of my other activities)
  2. Turn array into an array list
  3. Remove a string from that array (The current class name)
  4. Convert the list back into an array
  5. Get a random value from that array
  6. Execute method goToActivity with parameter of that random value

I have spent hours on this task so far, because the logic of the code seems fine. The problem is, when I run the code, I get the infamous error:

Unfortunately, "App_Name" has stopped

Here is my code for method onClick and goToActivity:

OnClick and goToActivity

Here is my array in the resources:

enter image description here

By the way, string activity state is the name of the activity :

enter image description here

I am sure the exception is in the method leftup, as none of the Toasts get executed, and the error happens immediately as I click on the button.

Thank you so much for all your help, I really appreciate it.

A fellow programmer,

{Rich}

Stack trace:

https://gist.github.com/anonymous/dcd63f51289aaf1a1933

Here is the stack trace because I couldn't format it, this is the git hub page.

Ruchir Baronia
  • 7,406
  • 5
  • 48
  • 83
  • 1
    Post your logcat output. It will tell you the exception, the source of the exception, the line where it came from... – takendarkk Oct 30 '15 at 00:37
  • @takendarkk Hey, thanks for your reply! I am pretty sure the exception is in this method, as none of the Toasts get executed, and the error happens immediately as I click on the button. – Ruchir Baronia Oct 30 '15 at 00:44
  • 1
    Rich, the logcat only where the stacktrace appeared. That thing with "java.exception" or something like that, usually in red, with some lines and file names together. Example: http://blogs.jetbrains.com/idea/wp-content/uploads/2010/03/screen-shot-2010-03-17-at-100031-am.png – George Oct 30 '15 at 00:49
  • @GeorgeRappel How do I get to that? I have looked it up, but cannot find it. – Ruchir Baronia Oct 30 '15 at 01:00
  • [What is a stack trace, and how can I use it to debug my application errors?](http://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors) – takendarkk Oct 30 '15 at 01:04
  • No you have not. Not only can I not see it in your question but the last edit on your question was 27 minutes ago. – takendarkk Oct 30 '15 at 01:13
  • @takendarkk It says that I have to format it. I am trying to format the code properly. I had posted that comment thinking I would post the stack trace right after. I am sorry for any confusions – Ruchir Baronia Oct 30 '15 at 01:15
  • @takendarkk https://gist.github.com/anonymous/dcd63f51289aaf1a1933 – Ruchir Baronia Oct 30 '15 at 01:22
  • @takendarkk Here is the stack trace. – Ruchir Baronia Oct 30 '15 at 01:24
  • @takendarkk According to it, this may be the error... arrayList.remove(activityState); – Ruchir Baronia Oct 30 '15 at 01:31
  • @takendarkk But I can't see what's wrong with it. Logically it makes sense. Thanks – Ruchir Baronia Oct 30 '15 at 01:32
  • @GeorgeRappel gist.github.com/anonymous/dcd63f51289aaf1a1933 – Ruchir Baronia Oct 30 '15 at 04:28
  • See, all you have to do is read the stacktrace :) Also, next time paste your code in text, not prints. – George Oct 30 '15 at 12:52

1 Answers1

0

I figured it out! After three long hours of tweaking the code, I finally got it! The arrayList had to be a linkedList. Thats it! Because, arrayList's aren't as flexible, and so one cannot remove or add items to them. I hope this answer helps, and saves you three long hours!

java.lang.UnsupportedOperationException
java.lang.reflect.InvocationTargetException

are the exceptions that happen on this issue. Just make sure to use a more flexible container. :)

{Rich}
Ruchir Baronia
  • 7,406
  • 5
  • 48
  • 83