ランダムなクラスを使って配列から別の運命を選ぶ占いアプリを作っています。多型に基づいています。私はそれをうまくコーディングしたことを知っていますが、私のアプリも開いていないでしょう、どんな助け?ここに私のコードは次のとおりです。ランダムなクラスの多型アンドロイド
public class fortuneList {
Random good = new Random();
Random bad = new Random();
public String getGood() {
String goodFortunes[] = new String[20];
int sel = 0;
for (int i = 0; i < 9; i++) {
sel = good.nextInt();
}
goodFortunes[0] = "Adel is awesome";
goodFortunes[1] = "Adel is cool";
goodFortunes[2] = "Adel is nice";
goodFortunes[3] = "Adel is gentle";
goodFortunes[4] = "Adel is smart";
goodFortunes[5] = "Adel is rich";
goodFortunes[6] = "Adel is good";
goodFortunes[7] = "This is 8";
goodFortunes[8] = "Change the quotes later";
return goodFortunes[sel];
}
public String getBad() {
String badFortunes[] = new String[5];
int sele = 0;
for (int is = 0; is < 5; is++) {
sele = bad.nextInt();
}
badFortunes[0] = "WTF";
badFortunes[1] = "Bad 1";
badFortunes[2] = "Nigga";
badFortunes[3] = "bish";
badFortunes[4] = "haha";
return badFortunes[sele];
}
}
、ここでは主な活動上の私のコードは次のとおりです。
public class MainActivity extends AppCompatActivity {
TextView fortuneText;
Random select = new Random();
ImageView ball;
Button button;
Drawable blue = getResources().getDrawable(R.drawable.blue);
Drawable red = getResources().getDrawable(R.drawable.red);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ball = (ImageView) findViewById(R.id.ball);
button = (Button) findViewById(R.id.button);
fortuneText = (TextView) findViewById(R.id.fortuneText);
}
public void getFortune(View view){
fortuneList obj = new fortuneList();
String fortuneType[]={obj.getGood(),obj.getBad()};
int fortuneSel = 0;
for(int i =0; i<2;i++){
fortuneSel = select.nextInt();
}
fortuneText.setText(fortuneType[fortuneSel]);
if (fortuneSel == 0) {
ball.setImageDrawable(blue);
}
if(fortuneSel == 1){
ball.setImageDrawable(red);
}
}
}
スタックトレースを投稿できますか? –