Good morning, I hope you can help me. I'm doing an internship on Android, and I'm stuck in a chapter about Activity and intents:
I have a List with several elements (places). I open a dialogue box where I enter the id and I open VistaLugar, where I can see the info of the place.
The problem comes at the time of opening the activity "Place Edition". In practice I must do that when pressing the Edit button from VistaLugar the "EditLink" view is opened, passing the id of the element that was open in the activity.
**
Unable to start activity ComponentInfo {com.example.dks.mislugaresdomingo / com.example.dks.mislugaresdomingo.EdicionLugar}: java.lang.ArrayIndexOutOfBoundsException: length = 10; index = -1
**
The question is: what happened to the current id (if that is what is missing, of course)
**
public class VistaLugar extends ActionBarActivity {
private long id;
private Lugar lugar;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.vista_lugar);
Bundle extras = getIntent().getExtras();
id = extras.getLong("id", -1);
lugar = Lugares.elemento((int)id);
..............
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
................
case R.id.accion_editar:
lanzaEdicionLugar((int)id);
return true;
....
public void lanzaEdicionLugar(int id) {
Intent i = new Intent(VistaLugar.this, EdicionLugar.class);
i.putExtra("id", id);
startActivity(i);
}
**
But I can not solve the problem. When it is executed from the other view VistaLugar this if it receives the parameters that have been entered from an AlertDialog:
public void lanzarVistaLugar(View view) { final EditText entrada = new EditText(this); ...... public void onClick(DialogInterface dialog, int witchButton){ long id = Long.parseLong(entrada.getText().toString()); Intent i = new Intent(MainActivity.this, VistaLugar.class); i.putExtra("id", id); startActivity(i);
public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.menu_buscar) { lanzarVistaLugar(null); return true; }