无法获得意图

时间:2015-07-07 14:49:20

标签: java android android-intent

我使用putextras将数据发送到其他页面

 Intent i = new Intent(Camerapage.this, Camera2.class);
      i.putExtra("mood","happy");
      i.putExtra("anger","anger");
      i.putExtra("fear","fear");
      startActivity(i);

当我收到它时

 mood.setText(intent.getStringExtra("mood"));
        happy.setText(String.valueOf(intent.getIntExtra("happiness",1)));
        fear.setText(String.valueOf(intent.getIntExtra("fear",1)));
         anger.setText(String.valueOf(intent.getIntExtra("anger",1)));

我试着评论知道它崩溃的地方......它有“心情”价值,但是当我要求愤怒和恐惧时它会崩溃......

4 个答案:

答案 0 :(得分:2)

试试这个

mood.setText(intent.getStringExtra("mood"));
    happy.setText(String.valueOf(intent.getStringExtra("happiness")));
    fear.setText(String.valueOf(intent.getStringExtra("fear")));
     anger.setText(String.valueOf(intent.getStringExtra("anger")));

答案 1 :(得分:0)

更改为getStringExtra()

   mood.setText(intent.getStringExtra("mood"));
   happy.setText(intent.getStringExtra("happiness"));
   fear.setText(intent.getStringExtra("fear"));
   anger.setText(intent.getStringExtra("anger"));

答案 2 :(得分:0)

永远不会设置happiness变量

happy.setText(String.valueOf(intent.getIntExtra("happiness")));

此外,您要发送String个值,因此请使用getStringExtra()代替getIntExtra()

答案 3 :(得分:-1)

在这一行你收到一个字符串:

 mood.setText(intent.getStringExtra("mood"));

但是在这一行中也是一个字符串,但你试着用getIntExtra()来获取值!

  happy.setText(String.valueOf(intent.getIntExtra("happiness",1)));
  fear.setText(String.valueOf(intent.getIntExtra("fear",1)));
  anger.setText(String.valueOf(intent.getIntExtra("anger",1)));

尝试使用getStringExtra()更改此行:

  mood.setText(intent.getStringExtra("mood"));
  happy.setText(intent.getStringExtra("happiness"));
  fear.setText(intent.getStringExtra("fear"));
  anger.setText(intent.getStringExtra("anger"));

并且记得您错过了从happiness

发送intent
 i.putExtra("happines",":)");