onbackpress应用程序崩溃了

时间:2016-01-11 11:37:51

标签: android nullpointerexception

我有三个活动A,B和C,现在我正在做的是,从活动A我发送一个数据到B

活动B

   Intent intent=getIntent();
    userids= intent.getStringExtra("userid");
    System.out.println("USERID BC"+userids);
    pname = intent.getStringExtra("names");
    occasions = intent.getStringExtra("oca");
    System.out.println("OC BC"+occasions);
    pics = intent.getStringExtra("photo");
    dates = intent.getStringExtra("datess");
    realtions = intent.getStringExtra("realations");
    friendid = intent.getStringExtra("friendid");

    System.out.println("Frnd BC"+friendid+userids);
    sendgift=(ImageView)findViewById(R.id.wishfriend_sendgift);
    ImageView propic=(ImageView)findViewById(R.id.wishfriend_propic);
    username=(TextView)findViewById(R.id.wishfriend_name);
    ocasions=(TextView)findViewById(R.id.wishfriend_occasion);
    datess=(TextView)findViewById(R.id.wishfriend_dates);
    pointshori=(HorizontalScrollView)findViewById(R.id.pointshori);
    yourLayout = (LinearLayout)findViewById(R.id.linearhori);
    selectedpoints=(TextView)findViewById(R.id.wishfrindselectdpoints);
    username.setText(pname);
    ocasions.setText(occasions);
    datess.setText("Date: " + dates);
    aQuery.id(propic).image(pics, true, true, 0, R.drawable.male);



    PLACE_URL = "http:///webservices/wish_friend.php?user_id="+userids+"&det="+friendid+"&occ="+ URLEncoder.encode(realtions);
    WISHU_URL = "http:///webservices/wish_friend.php?user_id="+userids;
    sendgift.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            if(edtmessages.getText().toString().trim().equals(""))
            {
                Toast.makeText(getApplicationContext(),"Enter Message",Toast.LENGTH_SHORT).show();
            }

            else if(giftpointss.toString().equals("0"))
            {
                Toast.makeText(getApplicationContext(),"Sorry you can not gift with 0 points",Toast.LENGTH_SHORT).show();
            }
            else
            {
                new AttemptLogin().execute();
            }

        }
    });



        new LoadAllPreset().execute();



        new LoadPlacestatus().execute();

工作正常,现在我要去B到C,但是当我从C回到B时我的应用程序崩溃了,得到空指针异常

这里

PLACE_URL = "http:///webservices/wish_friend.php?user_id="+userids+"&det="+friendid+"&occ="+ URLEncoder.encode(realtions);

1 个答案:

答案 0 :(得分:1)

在访问意图数据之前检查

if( getIntent().getExtras() != null){
      // intent has data
      Intent intent=getIntent();
      userids= intent.getStringExtra("userid");
      ...
}
else
{
      //probably you are from C->B after back press
}