Note that there are some explanatory texts on larger screens.

plurals
  1. PONext activity closed when trying to add editText
    primarykey
    data
    text
    <p>I want to add editText dynamically. But when I click on the button, the next activity is closed forcefully. It gives me a nullpointer exception in the log.</p> <p>When adding cotrol, is it needed to have control in the xml file for initialization??</p> <pre><code>package com.example.snooder; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; public class MainActivity extends Activity { EditText ed1; Button btn1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ed1 = (EditText) findViewById(R.id.editText1); btn1 =(Button) findViewById(R.id.button1); btn1.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Intent i = new Intent(MainActivity.this,players.class); i.putExtra("name",ed1.getText().toString()); startActivity(i); } }); } } </code></pre> <p>players.java</p> <pre><code>package com.example.snooder; import android.app.Activity; import android.os.Bundle; import android.widget.EditText; import android.widget.LinearLayout; public class players extends Activity { LinearLayout player_layout; Bundle b; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.players); b = getIntent().getExtras(); String resStr = b.getString("name"); player_layout = (LinearLayout) findViewById(R.id.player_layout); EditText[] ed1 = new EditText[Integer.parseInt(resStr)]; for(int i=1;i&lt;=Integer.parseInt(resStr);i++) { ed1[i] = new EditText(this); player_layout.addView(ed1[i]); ed1[i].setId(i); ed1[i].setHint("enter player's name"); ed1[i].setHeight(50); ed1[i].setWidth(500); } } } </code></pre>
    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