Androidスタジオに問題があり、作成しているランダマイザアプリケーションでsetOnClickListenerを解決できないようです。以下はアプリケーションのコードです。私は問題を特定できないようだが、どんな助けでも大いに感謝するだろう。AndroidスタジオがsetOnClickListenerを解決できない
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
TextView textOne = (TextView) findViewById(R.id.textView);
TextView textTwo = (TextView) findViewById(R.id.textView2);
TextView textThree = (TextView) findViewById(R.id.textView3);
TextView textFour = (TextView) findViewById(R.id.textView4);
TextView textFive = (TextView) findViewById(R.id.textView5);
TextView textSix = (TextView) findViewById(R.id.textView6);
TextView textSeven = (TextView) findViewById(R.id.textView7);
TextView textEight = (TextView) findViewById(R.id.textView8);
Button button = (Button) findViewById(R.id.button);
String[] myStamina = {"Stamina", "300%"};
String[] mySize = {"Off", "Mega", "Mini"};
String[] myHead = {"Off", "Flower", "Bunny"};
String[] myBody = {"Off", "Metal", "Clear", "Tail", "Rocket belt", "Screw", "Back shield"};
String[] myStatus = {"Off", "Curry", "Reflect"};
String[] myGravity = {"Off", "Light", "Heavy"};
String[] mySpeed = {"Off", "Fast", "Slow"};
String[] myCamera = {"Off", "Fixed", "Angled"};
int random1 = (int) ((Math.random() * 1));
int random2 = (int) ((Math.random() * 2));
int random3 = (int) ((Math.random() * 6));
button.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
textOne.setText(myStamina[random1]);
textTwo.setText(mySize[random2]);
textThree.setText(myHead[random2]);
textFour.setText(myBody[random3]);
textFive.setText(myStatus[random2]);
textSix.setText(myGravity[random2]);
textSeven.setText(mySpeed[random2]);
textEight.setText(myCamera[random2]);
}
});
}
あなたはメソッドの外にたくさんのコードを入れました...小さなセクションでアプリケーションをテストしてみてください –