How can I get the value of EditText then store it in my array?
This is my full code:
EditText op = (EditText)v.findViewById(R.id.operator);
array=new int [Integer.valueOf(op.getText().toString())];
for (i = 0;i<(array.length+1);i++){
LayoutInflater inflater = MainActivity.this.getLayoutInflater();
final View v2=inflater.inflate(R.layout.inputangka, null) ;
new AlertDialog.Builder(MainActivity.this)
.setIcon(R.drawable.ic_launcher)
.setTitle("number of-"+(i-1)+":")
.setView(v2)
.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
EditText number = (EditText)v2.findViewById(R.id.number);
int number1 = Integer.valueOf(number.getText().toString());
array [i]= number1; //error line
My error log:
02-05 16:33:31.374: E/AndroidRuntime(431): java.lang.ArrayIndexOutOfBoundsException
How do I solve this?
for (i = 0;i<(array.length+1);i++)- Seems like that's your problem. The +1 puts you beyond the last index in the array.