AndEngine에 대한 더 복잡한 용도로 다이빙을 시작했습니다. 멈추기 시작 했으므로 생각했습니다. 나는 알아낼 수없는 NPE를 만났기 때문에 어떤 도움을 주셔서 감사하겠습니다.RevoluteJointDef를 초기화 할 때의 NullPointerExceptions
아래의 클래스는 원유 래그 돌/stickman을 나타내며 클래스 자체는 모든 텍스처, 바디, 조인트 및 기타 등 록을 andengine에 등록합니다. 에 대한 그래서 유일한 물건,
this.skater = new Skater(this, mPhysicsWorld, new Vector2(startX, startY));
나는 대부분의 다른 관절과 팔다리에 같은 물건을 반복되는 몇 가지 코드를 멀리 손질했습니다 (SimpleBaseGameActivity를 확장)를 mainActivity는 초기화하는 동안 이런 식으로 생성자를 호출 발목 관절은 텍스트의 벽이 그대로 충분히 크므로 포함됩니다.
NPE는 생성자의 끝 부분이 라인에 발생합니다 :
this.jAnkle.initialize(bSkates, bLegs, new Vector2(stickmanPos.x, sSkates.getHeight()));
public class Stickman {
//////////////
// Constructor
public Stickman(Testgame game, PhysicsWorld engine, Vector2 stickmanPos) {
this.game = game;
this.engine = engine;
this.stickmanPos = stickmanPos;
// Create textures
textureAtlas = new BitmapTextureAtlas(game.getTextureManager(), 1024, 1024, TextureOptions.BILINEAR);
this.tSkates = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.textureAtlas, this.game, "stickman_skates.png", 0, 0, 2, 1);
this.tLegs = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.textureAtlas, this.game, "stickman_legs.png", 0, 0, 2, 1);
// --SNIPPED--
// Create sprites
this.sSkates = new AnimatedSprite(stickmanPos.x, stickmanPos.y, this.tSkates, game.getVertexBufferObjectManager());
this.sLegs = new AnimatedSprite(stickmanPos.x + skatesToLegs, stickmanPos.y, this.tLegs, game.getVertexBufferObjectManager());
// --SNIPPED--
// Create body with sprites
this.bSkates = PhysicsFactory.createBoxBody(engine, sSkates, BodyType.DynamicBody, game.FIX_SKATER);
this.bLegs = PhysicsFactory.createBoxBody(engine, sLegs, BodyType.DynamicBody, game.FIX_SKATER);
// --SNIPPED--
// Register bodies with Box2D
this.engine.registerPhysicsConnector(new PhysicsConnector(this.sSkates, this.bSkates, true, true));
this.engine.registerPhysicsConnector(new PhysicsConnector(this.sLegs, this.bLegs, true, true));
// --SNIPPED--
// Create joints
RevoluteJointDef jAnkle = new RevoluteJointDef();
System.out.println("aoeu aoeu aoeu aoeu");
this.jAnkle.initialize(bSkates, bLegs, new Vector2(stickmanPos.x, sSkates.getHeight()));
this.jAnkle.enableMotor = true;
this.jAnkle.motorSpeed = this.dex;
this.jAnkle.maxMotorTorque = this.str;
}
////////////////
// Fields
private Testgame game;
private PhysicsWorld engine;
private Vector2 stickmanPos;
// Config
private float skatesToLegs = 1;
private float legsToThigh = 1;
private float thighToTorso = 1;
private float torsoToHead = 1;
private float torsoToArms = 1;
// Stats
private float gli = 0; // Higher number = lower skate friction
private float str = 0; // Joint torque
private float dex = 0; // Joint speed
private float con = 0; // Impact tolerance
// JointPositions
private float shoulderPos;
private float neckPos;
private float hipPos;
private float kneePos;
protected BitmapTextureAtlas textureAtlas;
protected ITiledTextureRegion tSkates;
protected ITiledTextureRegion tLegs;
// --SNIPPED--
protected AnimatedSprite sSkates;
protected AnimatedSprite sLegs;
// --SNIPPED--
protected Body bSkates;
protected Body bLegs;
// --SNIPPED--
protected RevoluteJointDef jAnkle;
// --SNIPPED--
}
가 잘하면 내가했던 것을 분명히 멍청한 짓이 아니다. 그렇다면 용서해주세요.
jAnkle 변수가 섀도 잉되어있는 것을 볼 수는 있지만 NPE가 어떻게 발생하는지 알 수 없습니다. –
@HovercraftFullOfEels 섀도 잉이란 무엇을 의미합니까? – Jarmund
stickman 객체가 null 일 수도 있습니다. –