title: Java/LibGDX get sprite from userdata
body: <p>I'm trying to access a sprite from a fixtures userdata which should work fine, but gives me this error:</p>
  
  <pre><code>Exception in thread "LWJGL Application" java.lang.ClassCastException: java.lang.String cannot be cast to com.freeranger.colorcourse.entities.EvilE
  at com.freeranger.colorcourse.handlers.MyContactListener.beginContact(MyContactListener.java:74)
  at com.badlogic.gdx.physics.box2d.World.beginContact(World.java:985)
  at com.badlogic.gdx.physics.box2d.World.jniStep(Native Method)
  at com.badlogic.gdx.physics.box2d.World.step(World.java:689)
  at com.freeranger.colorcourse.screens.Play.update(Play.java:185)
  at com.freeranger.colorcourse.screens.Play.render(Play.java:202)
  at com.badlogic.gdx.Game.render(Game.java:46)
  at com.freeranger.colorcourse.Main.render(Main.java:139)
  at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:225)
  at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)
  </code></pre>
  
  <p>The code that causes the problem is this one:</p>
  
  <pre><code>String[] data = {"red", "orange", "yellow", "green", "blue", "pink", "orange_gravity_block"};
  for(int i = 0; i &lt; data.length; i++){
      if(fa.getUserData() != null &amp;&amp; fa.getUserData().equals(data[i])){
              if (fb.getUserData() != null &amp;&amp; fb.getUserData().equals("evile_left_sensor")) {
                  ((EvilE)fb.getUserData()).reverseVelocity(); //this causes error
              }else if (fb.getUserData() != null &amp;&amp; fb.getUserData().equals("evile_right_sensor")) {
                  ((EvilE)fb.getUserData()).reverseVelocity(); //this causes error
              }
          }   
      }
  </code></pre>
  
  <p>In my Play class this code sets the userdata to the Evil-E (enemy):</p>
  
  <pre><code> EvilE c = new EvilE(body, game);
   eviles.add(c);
   body.setUserData(c);
  </code></pre>
  
  <p>The collision all happens in my Contact Listener and the enemy I'm trying to access (EvilE) is in my Play class(PlayScreen).</p>
  
  <p>What's expected is for my enemies to change direction when they hit a wall, but they don't - instead the game crashes and I get the error I showed before. How do I fix this?</p>
  
  <p>Thanks!</p>