###前提・実現したいこと
ここに質問したいことを詳細に書いてください
すみません、初めて利用するのですが。どうしてもわからないことがあったのですが。
私はランダムに画像をいろんな位置に時間経過で表示していくプログラムを組んでいるのですが、
プログラムは見た感じ間違っていないような気がするのですがエラーが出てしまいます。
画像はXMLに書いたものをソース側で取り込んで使っています。
どこらへんが間違っているのでしょうか、私的には画像表示に配列に画像を使う事自体が間違っていると思ったのですがどうでしょうか?
###発生している問題・エラーメッセージ
エラーメッセージ
###該当のソースコード
JAVA
1 2 3public class MainActivity extends AppCompatActivity { 4 5 private Handler _handler = new Handler(); 6 Timer _timer ; 7 private Context applicationContext; 8 int i=0; 9 int k=0; 10 ImageView[] iview=new ImageView[100]; 11 int[] deta=new int[100]; 12 13 @Override 14 protected void onCreate(Bundle savedInstanceState) { 15 super.onCreate(savedInstanceState); 16 setContentView(R.layout.activity_main); 17 18 19 iview[0]=findViewById(R.id.a1); 20 iview[1]=findViewById(R.id.a2); 21 iview[2]=findViewById(R.id.a3); 22 iview[3]=findViewById(R.id.a4); 23 iview[4]=findViewById(R.id.a5); 24 iview[5]=findViewById(R.id.a6); 25 26 for(int u=0;u<6; u++) { 27 iview[u].setVisibility(View.GONE); 28 } 29 30 31 32 _timer = new Timer(); 33 _timer.schedule( new TimerTask(){ 34 @Override 35 public void run() { 36 _handler.post( new Runnable() { 37 public void run() { 38 39 RelativeLayout rel=findViewById(R.id.rel); 40 rel.addView(iview[i]); 41 //iview[i].setVisibility(View.VISIBLE); 42 // ImageViewからマージンを取得 43 ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams)iview[i].getLayoutParams(); 44// 移動させたい距離に変更 45 int t = (int)(Math.random()*800-100); 46 int n = (int)(Math.random()*800-100); 47 if(t>-100||n>-100){ 48 lp.topMargin = t; 49 lp.leftMargin = n;} 50// ImageViewへ反映 51 iview[i].setLayoutParams(lp); 52 53 i++; 54 55 if(i==2){ 56 57 _timer.cancel(); 58 59 } 60 } 61 }); 62 } 63 }, 0, 10000); 64 } 65} 66
###試したこと
課題に対してアプローチしたことを記載してください
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報