Lucas Camargo
Lucas Camargo

Reputation: 21

Android Bundle putStringArray not working

I'm want to pass three strings from one acticity to another, but it doesn't work. I've tried a lot but I just can't understand why it doesn't work this is the first activity

First activity

                          String[] g = new String[3];
                  g[0] = "information 1";
                g[1] = "information 2";
                g[2] = "information 3";
                Intent intent = new Intent(Entradas.this,Informacoes.class);
                Bundle bundle = new Bundle();
                bundle.putStringArray("some string",g);
                intent.putExtras(bundle);
                startActivity(intent);

Second Activity

        Bundle bundle = getIntent().getExtras();
    String[] abc = bundle.getStringArray("some string");
    TextView txtInfo= (TextView) findViewById(R.id.textViewInfo);
    txtInfo.setText(abc[0]);
    TextView txtNome= (TextView) findViewById(R.id.textViewNome);
    txtNome.setText(abc[1]);
    TextView txtPreco= (TextView) findViewById(R.id.textViewPreco);
    txtPreco.setText(abc[2]);

it just doesn't work, any ideas of how I can fix this?

Upvotes: 2

Views: 1347

Answers (1)

dodehoekspiegel
dodehoekspiegel

Reputation: 339

You have three elements but allocated space for 2. Tried fixing this first?

Upvotes: 1

Related Questions