我正在尝试将一个字符串从一个活动拉到另一个活动,但每次我尝试打开一个活动时,我都会在.getString
上获得一个forceclose。
Logcat错误
10-26 10:36:45.444: ERROR/AndroidRuntime(15112): at http.www.hotapp.com.timeandlocation.email.EmailSettings.onCreate(ThisActivity.java:29)
活动调用字符串
public class ThisActivity extends Activity{
private TextView reciever;
private String rec;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.elayout);
reciever = (TextView) findViewById (R.id.Reciver);
rec =
getIntent()
.getExtras()
.getString
("send");
reciever.setText(rec);
}
字符串
的活动public class OtherActivity extends Activity{
private EditText sendto;
private Button save;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.emailactivity);
sendto = (EditText) findViewById(R.id.sendto);
save = (Button) findViewById(R.id.Save);
save.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Intent intent = new Intent (EmailActivity.this,EmailSettings.class);
intent.putExtra("send", sendto.getText().toString());
startActivity(intent);
}
});
}
}
感谢您的帮助。
答案 0 :(得分:2)
尝试使用getIntent().getStringExtra("send");
如果您想检查额外是否有用:
getIntent().hasExtra("send");
答案 1 :(得分:1)
试试这个:
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
rec = extras.getString("send");
}
答案 2 :(得分:1)
通过从getString()函数
中消除NULL EXCEPTION来尝试这个