跳转Activity闪退

从活动A跳到活动B,如果用putExtra存入key-value值,在B中Bundle bun = this.getIntent.getString()方法会报错

从login到welcome报错,去掉welcome的Bundle就能通过

主要是77-85行
public class login extends Activity{
private static String url_create_product = "http://100.71.128.80/myproduct/denglu.php"; 
     private static final String TAG_SUCCESS = "success"; 
     private ProgressDialog pDialog; 
JSONParser jsonParser = new JSONParser(); 
EditText usern,userp;
Button zhuce,denglu;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.log_in);
usern=(EditText)findViewById(R.id.usern);
userp=(EditText)findViewById(R.id.userp);
zhuce=(Button)findViewById(R.id.zhuce);
denglu=(Button)findViewById(R.id.denglu);

zhuce.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent it = new Intent(); 
it.setClass(getApplicationContext(), zhuce.class);
startActivity(it);
}

});

denglu.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(usern.length()!=0&&userp.length()!=0)
new LogUser().execute();
else Toast.makeText(getApplicationContext(), "empty", Toast.LENGTH_SHORT).show();
}
});

}


class LogUser extends AsyncTask<String, String, String> {

@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pDialog = new ProgressDialog(login.this); 
pDialog.setMessage("Loging.."); 
pDialog.setIndeterminate(false); 
pDialog.setCancelable(true); 
pDialog.show(); 
}

@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub

String name = usern.getText().toString(); 
String passwd = userp.getText().toString();


List<NameValuePair> para = new ArrayList<NameValuePair>(); 
para.add(new BasicNameValuePair("name", name)); 
para.add(new BasicNameValuePair("passwd", passwd)); 
// getting JSON Object 
// Note that create product url accepts POST method 
JSONObject json = jsonParser.makeHttpRequest(url_create_product, 
"POST", para); 
// check log cat fro response 
Log.d("Create Response", json.toString()); 
// check for success tag 
try{ 
int success = json.getInt(TAG_SUCCESS); 
if(success == 1) { 
String info = json.getString("product");
Intent it= new Intent();

it.setClass(getApplicationContext(),welcome.class);
Bundle bundle = new Bundle();
bundle.putString("inf", info);
//it.putExtra("fahuoren", name);

startActivity(it);
} else{ 
// failed to create product 
//Toast.makeText(getApplicationContext(), " 111",Toast.LENGTH_SHORT).show();

} catch(JSONException e) { 
e.printStackTrace(); 



return null;
}



@Override
protected void onPostExecute(String fil_url) {
// TODO Auto-generated method stub
pDialog.dismiss();
}

}

}


public class welcome extends Activity {

TextView tv;
Button btf;
Intent itt = getIntent();
Bundle bun = itt.getExtras();
String information = bun.getString("inf");
String name = bun.getString("fahuoren");
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);

tv=(TextView)findViewById(R.id.tv);
//tv.setText(information);
btf=(Button)findViewById(R.id.btf);
btf.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent it = new Intent();
it.setClass(getApplicationContext(),fahuo.class);
//it.putExtra("usen", information);
startActivity(it);
}
});
}

}

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值