Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
nischal95
nischal95's Profile
1
Posts
1
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
NullPointException
[4 Replies]
22-Jun-2013 12:26 PM
Forum:
Android Processing
FATAL EXCEPTION: Animation Thread
java.lang.NullPointerException
at android.graphics.Bitmap.checkPixelsAccess(Bitmap.java:1195)
at android.graphics.Bitmap.setPixels(Bitmap.java:1257)
at processing.core.PGraphicsAndroid2D.imageImpl(Unknown Source)
at processing.core.PGraphics.image(Unknown Source)
at processing.core.PApplet.image(Unknown Source)
at processing.test.square.square.playEngine(square.java:121)
at processing.test.square.square.draw(square.java:68)
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:856)
i am a little new to processing. my code is as follows:
int ballx, bally, posx, posy, speed, score, score_tens,
score_units, score_hundreds, score_temp, button_pos_x,
button_pos_y, pad_pos, upper_wall, red, green, blue, distance;
boolean running, increase;
PImage pad, ball, pause, play, exit;
PImage [] score_img;
void setup() {
size(720, 640);
bally = height/2;
ballx = width/2;
posx = posy = 1;
speed = 2;
score = 0;
red = green = blue = 50;
button_pos_x = width/2;
button_pos_y = height/30;
pad_pos = 4*(height/5) + height/8;
running = true;
increase = true;
score_tens = score_units = score_hundreds = 0;
pad = loadImage("png/pad.png");
ball = loadImage("png/ball.png");
play = loadImage("png/play.png");
pause = loadImage("png/pause.png");
exit = loadImage("png/exit.png");
score_img = loadImages("png/score_", ".png", 10);
upper_wall = height/45 + score_img[0].height;
pad.resize(width/7, 0);
imageMode(CENTER);
}
void draw() {
score_units = score % 10;
score_temp = score / 10;
score_tens = score_temp % 10;
score_hundreds = score_temp / 10;
if (running) {
playEngine();
ballPositionAndDirection();
if ((bally + ball.height/2 == pad_pos - pad.height/2)
&& ((ballx >= mouseX - pad.width/2) &&
(ballx <= mouseX + pad.width/2)))
{
posy = 0;
Raptor();
++score;
}
if (bally > pad_pos)
{
bally = 50;
speed = 2;
score = 0;
}
}
else {
paused();
}
}
void mousePressed() {
if (((mouseX >= button_pos_x - pause.width/2) &&
(mouseX <= button_pos_x + pause.width/2)) &&
(mouseY >= button_pos_y - pause.height/2) &&
(mouseY <= button_pos_y + pause.height/2))
running = !running;
if ((mouseX >= width - exit.width - exit.width/2) &&
(mouseX <= width - exit.width + exit.width/2)&&
(mouseY >= button_pos_y - exit.height/2) &&
(mouseY <= button_pos_y + exit.height/2))
exit();
}
void playEngine() {
colourEngine();
background(red, green, blue);
image(pause, button_pos_x, button_pos_y);
line(0, upper_wall, width, upper_wall);
image(exit, width - exit.width, button_pos_y);
if ((mouseX < pad.width/2))
image(pad, pad.width/2, pad_pos);
else if (mouseX > (width - pad.width/2))
image(pad, width - pad.width/2, pad_pos);
else
image(pad, mouseX, pad_pos);
image(ball, ballx, bally);
image(score_img[score_hundreds], width/12, button_pos_y);
image(score_img[score_tens], width/12 +
score_img[0].width + 3, button_pos_y);
image(score_img[score_units], width/12 +
(2*(score_img[0].width)) + 6, button_pos_y);
}
void paused() {
background(red, green, blue);
line(0, upper_wall, width, upper_wall);
image(exit, width - exit.width, button_pos_y);
image(score_img[score_hundreds], width/12, button_pos_y);
image(score_img[score_tens], width/12 +
score_img[0].width + 3, button_pos_y);
image(score_img[score_units], width/12 +
(2*(score_img[0].width)) + 6, button_pos_y);
image(play, button_pos_x, button_pos_y);
image(pad, mouseX, pad_pos);
image(ball, ballx, bally);
}
void ballPositionAndDirection() {
if (ballx + ball.width/2 >= width)
posx = 0;
if (ballx - ball.width/2 <= 0)
posx = 1;
if (bally + ball.height/2 >= height)
posy = 0;
if (bally - ball.height/2 <= upper_wall)
posy = 1;
if (posx == 0)
ballx -= speed;
else
ballx += speed;
if (posy == 0)
bally -= speed;
else
bally += speed;
}
void colourEngine() {
if (increase) {
red += 1;
green += 1;
blue += 1;
if (red == 200)
increase = false;
}
else {
red -= 1;
green -= 1;
blue -= 1;
if (red == 50)
increase = true;
}
}
void Raptor() {
distance = int(dist(ballx, bally, mouseX, pad_pos));
speed = int(sqrt((2*distance) + 1));
}
i am running this on a device through adb.
and btw.. it works in java mode. is it something to do with my device?
thanks in advance
«Prev
Next »
Moderate user : nischal95
Forum