java - Game Crashes when adding to array or linker List -


so i'm having issue adding arraylist or linked list (tried both, each crash same). i'm working off of andengine tutorial (jimvaders, worked fine), when adapting own project, isn't working properly. basically, when shoot bullet, gets added list of bullets, in project, trying touch arraylist or linkedlist, located in gamescene, playerchar class causes whole game crash. haven't done list yet, it's act of adding playerbullet list causing problem far can tell.

gamescene:

public arraylist<playerbullet> bulletlist; 

in playerchar class

public void shoot(int playerfacing) { //todo      gamescene scene = (gamescene) baseactivity.getsharedinstance().getcurrentscene();     float shootx = 2;      playerbullet b =(playerbullet)playerbulletpool.sharedbulletpool().obtainpoolitem();      if (playerfacing == -1){         shootx *= -1;     }     else{         shootx += this.getwidth();     }       b.sprite.setposition(this.getx() + shootx, this.gety()+(this.getheight()/2));     movexmodifier mod = new movexmodifier(0.5f, b.sprite.getx(), mcamera.getcenterx() + (mcamera.getwidth()*playerfacing));      b.sprite.setvisible(true);     b.sprite.detachself();     scene.attachchild(b.sprite);     //log.v("checkin", "works here");     scene.bulletlist.add(b);//<---------crashes here, works fine if line commented out      //log.v("checkin", "still working?");     b.sprite.registerentitymodifier(mod);  } 

any insight helpful. thanks

my guess you've got nullpointerexception, although if you'd told us. line:

scene.bulletlist.add(b); 

requires both scene , scene.bulletlist non-null. can tell scene non-null, suspect scene.bulletlistis null - think you're initializing it?

(as aside, advise avoid public variables. put addbullet method gamescene - , make type of now-private bulletlist variable list<playerbullet>... specify arraylist<e> when initializing variable.)


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -