Note that there are some explanatory texts on larger screens.

plurals
  1. POReason behind android app crashes when button is clicked
    primarykey
    data
    text
    <p>I'm trying to make an app which creates an object and saves it in a TreeSet but when I press the button the app crashes. I need help</p> <p>MainActivity is as below:</p> <pre><code>public class MainActivity extends Activity { private TreeSet&lt;Variable&gt; arbreDeVariables = new TreeSet&lt;Variable&gt;(); protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); creeUneVariable(); } private void creeUneVariable() { Button boutonEnvoyer = (Button)findViewById(R.id.button1); boutonEnvoyer.setOnClickListener(new OnClickListener(){ public void onClick(View v) { Variable variable = new Variable(getUsername(), getPassword()); arbreDeVariables.add(variable); } }); } private String getUsername(){ final EditText username = (EditText)findViewById(R.id.editText1); return username.getText().toString(); } private String getPassword(){ final EditText password = (EditText)findViewById(R.id.editText2); return password.getText().toString(); } } </code></pre> <p>"Variable" class is as below:</p> <pre><code>public class Variable { private String username; private String password; public Variable(String username,String password){ this.username = username; this.password = password; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String toString(){ return "Username: "+username+" Password: "+password; } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    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.
    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