Get the Error "FATAL EXCEPTION: Animation Thread" everytime I compile my app

edited January 2014 in Android Mode

Hi,

I'm pretty new to android programming, I wanted to programm the game "Snake" (if some of you can remember this game from the old cellphones :D) for android I got a tutorial from my teacher for that.

But everytime I try to compile it I get this error message:

FATAL EXCEPTION: Animation Thread
java.lang.IllegalArgumentException: Host name may not be null
    at org.apache.http.HttpHost.<init>(HttpHost.java:83)
    at org.apache.http.impl.client.AbstractHttpClient.determineTarget(AbstractHttpClient.java:497)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
    at processing.core.PApplet.createInputRaw(Unknown Source)
    at processing.core.PApplet.createInput(Unknown Source)
    at processing.core.PApplet.loadImage(Unknown Source)
    at processing.test.snake3.Snake3.setup(Snake3.java:61)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:1019)

My whole code looks like this:

// imports
import android.view.MotionEvent;
import ketai.ui.*;

// gesture control
KetaiGesture gesture;
String direction;
float angle;

// values for the game
int DOT_SIZE = 10;
int ALL_DOTSX;
int ALL_DOTSY;
int WIDTH;
int HEIGHT;
int RAND_POS = 29;

int[] x;
int[] y;

int dots;
int apple_x;
int apple_y;

boolean left = false;
boolean right = true;
boolean up = false;
boolean down = false;
boolean inGame = true;

// images
PImage ball;
PImage apple;
PImage head;

// Setup
void setup() {
  gesture = new KetaiGesture(this);
  background(0);
  apple = loadImage("H:/Daten/Privat/Schule/Ausbildung/Berufsschule/Android%20Programmierung/Snake3/apple.png");  
  ball = loadImage("H:/Daten/Privat/Schule/Ausbildung/Berufsschule/Android%20Programmierung/Snake3/dot.png");  
  head = loadImage("H:/Daten/Privat/Schule/Ausbildung/Berufsschule/Android%20Programmierung/Snake3/head.png");  

  println("size: " + width + "x" + height);// 480x800
  WIDTH=width;
  HEIGHT=height;
  ALL_DOTSX = WIDTH * 3;
  ALL_DOTSY = HEIGHT * 3;
  x = new int[ALL_DOTSX];
  y = new int[ALL_DOTSY];

  dots = 3;
  for (int z = 0; z < dots; z++) {
     x[z] = 50 - z * 10;
     y[z] = 50;
  }
  locateApple();
  frameRate(3);
}

// gestures
public boolean surfaceTouchEvent(MotionEvent event) {
  super.surfaceTouchEvent(event);
  return gesture.surfaceTouchEvent(event);
}

// Display drawing
void draw() {

  if (inGame) {
    checkApple();
    checkCollision();
    move();

    // draw
    background(0);// clear the dispaly
    image(apple,apple_x,apple_y);

    for (int z = 0; z < dots; z++) {
      if (z == 0) {
        image(head, x[z], y[z]);
      } else {
        image(ball, x[z], y[z]);
      }
    }
  } else {
    background(255, 204, 0);
    fill(255);
    textSize(70);
    textAlign(CENTER, CENTER);
    text("Game Over", width/2,height/2);
    noLoop();
  }
}

void checkApple() {
  if ((x[0] == apple_x) && (y[0] == apple_y)) {
     dots++;
     locateApple();
  }
}

void move() {
  for (int z = dots; z > 0; z--) {
    x[z] = x[(z - 1)];
    y[z] = y[(z - 1)];
  }

  if (left) {
    x[0] -= DOT_SIZE;
  }
  if (right) {
    x[0] += DOT_SIZE;
  }
  if (up) {
    y[0] -= DOT_SIZE;
  }
  if (down) {
    y[0] += DOT_SIZE;
  }
}

void checkCollision() {
  for (int z = dots; z > 0; z--) {
    if ((z > 4) && (x[0] == x[z]) && (y[0] == y[z])) {
      inGame = false;
    }
  }

  if (y[0] > HEIGHT-dots*DOT_SIZE) {
    inGame = false;
  }
  if (y[0] < 0) {
    inGame = false;
  }
  if (x[0] > WIDTH-dots*DOT_SIZE) {
    inGame = false;
  }
  if (x[0] < 0) {
    inGame = false;
  }
}

void locateApple() {
    int r = (int)random(0, RAND_POS);
    apple_x = ((r * DOT_SIZE));
    r = (int)random(0, RAND_POS);;
    apple_y = ((r * DOT_SIZE));
}

// reacting to gestures
void onFlick( float x, float y, float px, float py, float v) {
  angle = (float)(Math.atan2(px-x,py-y)  * 180 / PI);
  if (angle >= -45 && angle <=45) {
    direction="UP";
    if (!down) {
      up = true;
      right = false;
      left = false;
    }
  } else if (angle > 45 && angle <= 135) {
    direction="LEFT";
    if (!right) {
      left = true;
      up = false;
      down = false;
     }
  } else if (angle > - 135 && angle <= -45 ) {
    direction="RIGHT";
    if (!left) {
      right = true;
      up = false;
      down = false;
    }
  } else {
    direction="DOWN";
    if (!up) {
      down = true;
      right = false;
      left = false;
    }
  }
  println(direction);
}

I just can't figure out where I did something wrong, I'm using Processing 2.03 (Processing 2.1 and higher aren't working I always get a build.xml error with them).

I would appreciate if someone could help me with this problem :)

Cheers Stephan

Answers

  • Answer ✓

    You should not use an absolute path to a resource! Perhaps it can work in an emulator (but apparently not), but it sure won't work in a phone!

  • ok but when i didn't use the absolute path than i get this error:

    Could not find the image apple.png.
    Could not find the image dot.png.
    Could not find the image head.png.
    size: 1280x720
    FATAL EXCEPTION: Animation Thread
    java.lang.NullPointerException
        at processing.core.PGraphics.image(Unknown Source)
        at processing.core.PApplet.image(Unknown Source)
        at processing.test.snake3.Snake3.draw(Snake3.java:98)
        at processing.core.PApplet.handleDraw(Unknown Source)
        at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
        at processing.core.PApplet.run(Unknown Source)
        at java.lang.Thread.run(Thread.java:1019)
    

    The pictures are in the same folder as the .pde file

  • ah no my question isn't answered why did it get marked as answered -.-

  • Answer ✓

    Try putting the images in the data folder, which is in the sketch folder.

    Your error message is fairly explicit, stating that Processing cannot find the images (see the first three lines).

  • ah thank you! i didn't have a data folder in the sketch folder so the pictures where right in the sketch folder and on the processing class site for image it only said it needs to be in the sketch folder. thats why i didn't understand why he couldn't find the pictures and tried it at first with absolute paths :)

    Thank you very much for the help :)

Sign In or Register to comment.