我正在尝试打开放置在路径" sketchfolder / data / 1024x768 / gulli2.png"的图像。它在Windows上工作正常,但它不能在Android上工作并给出错误。这是错误:
找不到图像\ 1024x768 \ gulli2.png。致命异常: 动画线程进程:processing.test.exercise_5_3_noisechain, PID:11878 java.lang.NullPointerException at processing.test.exercise_5_3_noisechain.Exercise_5_3_NoiseChain $ Gulli。(Exercise_5_3_NoiseChain.java:112) 在 processing.test.exercise_5_3_noisechain.Exercise_5_3_NoiseChain.setup(Exercise_5_3_NoiseChain.java:37) 在processing.core.PApplet.handleDraw(未知来源)at processing.core.PGraphicsAndroid2D.requestDraw(未知来源)at processing.core.PApplet.run(未知来源)at java.lang.Thread.run(Thread.java:841)
我正在尝试的代码:
class Gulli {
Body body;
float w;
float h;
float angle;
PImage img;
Gulli(float x_, float y_) {
float x = x_;
float y = y_;
w = (float)(width*2.2/100.0);
h = w/2;
img = loadImage("\\1024x768\\gulli2.png");
img.loadPixels();
img.resize((int)w*2,0);
img.updatePixels();
angle = 0;
makeBody(new Vec2(x, y), w, h, angle);
}
void makeBody(Vec2 center, float w_, float h_, float a) {
BodyDef bd = new BodyDef();
bd.position.set(box2d.coordPixelsToWorld(center));
bd.setAngularVelocity(a);
bd.type = BodyType.DYNAMIC;
bd.bullet = true;
body = box2d.createBody(bd);
PolygonShape sd = new PolygonShape();
Vec2 []vertices = new Vec2[6];
vertices[0] = new Vec2(box2d.scalarPixelsToWorld(w), 0);
vertices[1] = new Vec2(box2d.scalarPixelsToWorld(h), box2d.scalarPixelsToWorld(h/3));
vertices[2] = new Vec2(box2d.scalarPixelsToWorld(-h), box2d.scalarPixelsToWorld(h/3));
vertices[3] = new Vec2(box2d.scalarPixelsToWorld(-w), 0);
vertices[4] = new Vec2(box2d.scalarPixelsToWorld(-h), box2d.scalarPixelsToWorld(-h/3));
vertices[5] = new Vec2(box2d.scalarPixelsToWorld(h), box2d.scalarPixelsToWorld(-h/3));
sd.set(vertices, vertices.length);
FixtureDef fd = new FixtureDef();
fd.shape = sd;
fd.density = 4.0;
fd.friction = 0.6;
fd.restitution = 0.3;
body.createFixture(fd);
bd.allowSleep = false;
body.setUserData(this);
}
void display() {
Vec2 pos = box2d.getBodyPixelCoord(body);
float a = body.getAngle();
Fixture f = body.getFixtureList();
PolygonShape ps = (PolygonShape) f.getShape();
pushMatrix();
translate(pos.x, pos.y);
rotate(-a);
image(img, 0, 0);
popMatrix();
}
}
import shiffman.box2d.*;
import org.jbox2d.collision.shapes.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.*;
Box2DProcessing box2d;
Gulli gulli;
void setup() {
// size(1024, 768); // turn on for windows
box2d = new Box2DProcessing(this);
box2d.createWorld();
gulli = new Gulli((float)width*15.0/100.0, (float)height*95.0/100.0);
smooth();
}
void draw() {
gulli.display();
box2d.step();
}
Plz帮助......谢谢..
答案 0 :(得分:0)
您的日志显示NullPointerException错误,这意味着您尝试指向不存在的图像。 尝试包括整个路径。没有双斜线" //"。 如果您正在使用URI格式,那么控件可能不支持这些格式。如果是这种情况,请先下载图像,然后加载它。