Note that there are some explanatory texts on larger screens.

plurals
  1. POButton to transfer me to next page and start a game
    primarykey
    data
    text
    <p>It's hard to explain in the title. Basically as far as I can tell the submit button is taking the name and placing it in the array like I want. What I need now is for the Play(done) Button to transfer the user and the data to the next class (which I believe is coded correctly) and I need it to start a game. The game which you will see in the second class (get the data from the previous) I need it to display the names from the names array 1 at a time and randomly assign them a task to do from the tasks array. </p> <p>Currently the app is force closing after I click the play button. I'm linking both classes cause I'm pretty sure the problem is in the second class. Thanks for your help ahead of time.</p> <p>Class1</p> <pre><code>public class Class1 extends Activity { int players=0; String names[]; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.class1); final EditText input = (EditText) findViewById(R.id.nameinput); final ArrayList&lt;String&gt; names = new ArrayList&lt;String&gt;(); Button submitButton = (Button) findViewById(R.id.submit_btn); submitButton.setOnClickListener(new View.OnClickListener() { public void onClick(View submit1) { players++; for(int i=0; i &lt; 6; i++) { names.add(input.getText().toString()); input.setText(""); } } }); Button doneButton = (Button) findViewById(R.id.done_btn); doneButton.setOnClickListener(new View.OnClickListener() { public void onClick(View done1) { Intent done = new Intent(Class1.this, Game.class); Bundle bundle = new Bundle(); bundle.putStringArrayList("arrayKey", names); done.putExtra("players", players); //done.putExtra("names", names[players]); startActivity(done); } }); } </code></pre> <p>Game Class</p> <pre><code>public class Game extends Activity { int players, counter=0, score, ptasks,rindex; String[] names, tasks; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.game); Bundle bundle = this.getIntent().getExtras(); String[] names = bundle.getStringArray("arrayKey"); Intent game = getIntent(); players = game.getIntExtra("players", 1); //names = game.getStringArrayExtra("names"); Random generator = new Random(); tasks[0]= ""; tasks[1]= ""; tasks[2]= ""; tasks[3]= ""; tasks[4]= ""; tasks[5]= ""; tasks[6]= ""; tasks[7]= ""; tasks[8]= ""; tasks[9]= ""; while (counter &lt;5) { for (int i = 0; i &lt; players; i++) { TextView name1 = (TextView) findViewById(R.id.pname); name1.setText( names[i]+":"); ptasks = 10; rindex = generator.nextInt(ptasks); TextView task = (TextView) findViewById(R.id.task); task.setText( tasks[rindex]); } Button failButton = (Button) findViewById(R.id.fail_btn); failButton.setOnClickListener(new View.OnClickListener() { public void onClick(View failed) { } }); Button notButton = (Button) findViewById(R.id.notbad_btn); notButton.setOnClickListener(new View.OnClickListener() { public void onClick(View notbad) { } }); Button champButton = (Button) findViewById(R.id.champ_btn); champButton.setOnClickListener(new View.OnClickListener() { public void onClick(View champp) { } }); counter++; } } </code></pre> <p>Thought I should also mention that these buttons on the 2nd page I would like to assign a score to whichever name array person is up and keep track until the final round where it will display the winner. If anyone has any idea how to make that work.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload