Answer the question
In order to leave comments, you need to log in
How to properly create an array of objects in java?
There is a code:
@Override
public void run() {
sprite = new Sprite(this, man);
for(int i = 0; i < colvo; i++){
meteor[i] = new Meteor(this, meteorit);
}
while(update){
if(!holder.getSurface().isValid()) {
continue;
}
Canvas c = holder.lockCanvas();
onMyDraw(c);
holder.unlockCanvasAndPost(c);
}
}
meteor[i] = new Meteor(this, meteorit);
public class MySurfaceView extends SurfaceView implements Runnable{...}
public class MainActivity extends Activity implements View.OnTouchListener{...}
Answer the question
In order to leave comments, you need to log in
If only you could see how meteor is declared... Most likely you didn't make new to it (the array).
You can also use ArrayList.
No one uses arrays directly, well, only in some exotic cases. Use collections. ArrayList is fine for you.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question