
06-17 22:44:25.809: E/AndroIDRuntime(20526): FATAL EXCEPTION: UpdateThread06-17 22:44:25.809: E/AndroIDRuntime(20526): java.lang.NullPointerException06-17 22:44:25.809: E/AndroIDRuntime(20526): at org.andengine.util.modifIEr.ModifIErList.onUpdate(ModifIErList.java:66)06-17 22:44:25.809: E/AndroIDRuntime(20526): at org.andengine.entity.Entity.onManagedUpdate(Entity.java:1392)06-17 22:44:25.809: E/AndroIDRuntime(20526): at org.andengine.entity.Entity.onUpdate(Entity.java:1167)06-17 22:44:25.809: E/AndroIDRuntime(20526): at org.andengine.entity.Entity.onManagedUpdate(Entity.java:1402)06-17 22:44:25.809: E/AndroIDRuntime(20526): at org.andengine.entity.scene.Scene.onManagedUpdate(Scene.java:284)06-17 22:44:25.809: E/AndroIDRuntime(20526): at org.andengine.entity.Entity.onUpdate(Entity.java:1167)06-17 22:44:25.809: E/AndroIDRuntime(20526): at org.andengine.engine.Engine.onUpdateScene(Engine.java:591)06-17 22:44:25.809: E/AndroIDRuntime(20526): at org.andengine.engine.Engine.onUpdate(Engine.java:586)06-17 22:44:25.809: E/AndroIDRuntime(20526): at org.andengine.engine.Engine.onTickUpdate(Engine.java:548)06-17 22:44:25.809: E/AndroIDRuntime(20526): at org.andengine.engine.Engine$UpdateThread.run(Engine.java:820)
这是我的代码:
public class TestGFX2Activity extends SimpleBaseGameActivity implements IaccelerationListener,IOnScenetouchListener {/** Called when the activity is first created. */ private static final int CAMERA_WIDTH = 720; private static final int CAMERA_HEIGHT = 480; private final FixtureDef FIXTURE_DEF = PhysicsFactory.createFixtureDef(1,0.5f,0.5f); private BitmapTextureAtlas mBitmapTextureAtlas; private TextureRegion circleTR; private Scene scene; boolean down=false; float scale; final float growRate = (float) .0001; private PhysicsWorld mPhysicsWorld; @OverrIDe public EngineOptions onCreateEngineOptions() { final Camera camera = new Camera(0,CAMERA_WIDTH,CAMERA_HEIGHT); return new EngineOptions(true,ScreenorIEntation.LANDSCAPE_FIXED,new RatioResolutionPolicy(CAMERA_WIDTH,CAMERA_HEIGHT),camera); } @OverrIDe public voID onCreateResources() { /*line 66*/ this.mBitmapTextureAtlas = new BitmapTextureAtlas(this.getTextureManager(),64,128,TextureOptions.BIliNEAR); //line 66 this.circleTR = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlas,this,"circle.png",0); // 64x32 this.mBitmapTextureAtlas.load(); } @OverrIDe public Scene onCreateScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); this.scene = new Scene(); this.scene.setBackground(new Background(0,1,0)); Log.e("Tag","Got to background"); this.scene.setonScenetouchListener(this); this.mPhysicsWorld = new PhysicsWorld(new Vector2(0,SensorManager.GraviTY_EARTH),false); final VertexBufferObjectManager vertexBufferObjectManager = this.getVertexBufferObjectManager(); final Rectangle ground = new Rectangle(0,CAMERA_HEIGHT - 2,2,vertexBufferObjectManager); final Rectangle roof = new Rectangle(0,vertexBufferObjectManager); final Rectangle left = new Rectangle(0,CAMERA_HEIGHT,vertexBufferObjectManager); final Rectangle right = new Rectangle(CAMERA_WIDTH - 2,vertexBufferObjectManager); final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0,0.5f); PhysicsFactory.createBoxBody(this.mPhysicsWorld,ground,BodyType.StaticBody,wallFixtureDef); PhysicsFactory.createBoxBody(this.mPhysicsWorld,roof,left,right,wallFixtureDef); this.scene.attachChild(ground); this.scene.attachChild(roof); this.scene.attachChild(left); this.scene.attachChild(right); this.scene.registerUpdateHandler(this.mPhysicsWorld); return this.scene; } @OverrIDe public boolean onScenetouchEvent(final Scene pScene,final touchEvent pScenetouchEvent) { Sprite face; Body body; scale = 1; if(this.mPhysicsWorld != null) { if(pScenetouchEvent.isActionDown()) { //this.addFace(pScenetouchEvent.getX(),pScenetouchEvent.getY()); down = true; face = new Sprite(pScenetouchEvent.getX(),pScenetouchEvent.getY(),circleTR,this.getVertexBufferObjectManager()); body = PhysicsFactory.createBoxBody(this.mPhysicsWorld,face,BodyType.DynamicBody,FIXTURE_DEF); new Thread(new Grow(face)).start(); return true; } else if(pScenetouchEvent.isActionUp()){ down = false; } } return false; } @OverrIDe public voID onaccelerationAccuracyChanged(final accelerationData paccelerationData) { } @OverrIDe public voID onaccelerationChanged(final accelerationData paccelerationData) { final Vector2 gravity = Vector2Pool.obtain(paccelerationData.getX(),paccelerationData.getY()); this.mPhysicsWorld.setGravity(gravity); Vector2Pool.recycle(gravity); } @OverrIDe public voID onResumeGame() { super.onResumeGame(); this.enableaccelerationSensor(this); } @OverrIDe public voID onPauseGame() { super.onPauseGame(); this.disableaccelerationSensor(); } private class Grow implements Runnable{ Sprite s; ScaleModifIEr mod; public Grow(Sprite sprite){ s = sprite; scene.attachChild(s); } public voID run(){ while(down){ //Log.e("Tag",float.toString(scale)); s.clearEntityModifIErs(); mod = new ScaleModifIEr((float) .1,scale,scale+growRate); scale+=growRate; s.registerEntityModifIEr(mod); /*s.detachSelf(); s.setScale(scale); scale += growRate; try{ Thread.sleep(100); }catch(InterruptedException e){} scene.attachChild(s);*/ } } }}解决方法 你可能应该调用它,而不是在单独的Thread中调用它 new Grow(face)).start();
在runOnUpdate()块中,如
myActivity.runonUpdateThread(new Grow(face)));总结
以上是内存溢出为你收集整理的为什么我得到更新线程空指针异常(Android AndEngine)?全部内容,希望文章能够帮你解决为什么我得到更新线程空指针异常(Android AndEngine)?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)