2012-11-10 76 views
2

我想从一个acticity传递三个字符串到另一个,但它不起作用。我已经尝试了很多,但我只是不明白为什么它不工作 这是第一个活动Android捆绑putStringArray不工作

第一项活动

      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); 

次活动

 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]); 

它只是不工作,我怎么能解决这个问题的任何想法?

+4

String [] g = new String [3]; – waqaslam

+0

而这段代码没有崩溃?在线:g [2] =“信息3”;有趣的... – yahya

+0

你能确切地说*如何*它不起作用?你得到什么,哪些错误... – davidcesarino

回答

1

你有三个元素,但为2分配空间。试图先解决这个问题?

+0

这是正确的,但它也没有工作 –