我正在将值从“活动A”发送到“活动B”,并且将数据设置为视图,它工作正常,但是当我按“后退”按钮时,它正在nullpointerexpection
方法中返回textView.setText()
。我已实现如下:
Intent i = getIntent();
serialArrayList = i.getParcelableExtra("member_list");
gridView = (GridView) findViewById(R.id.officerGrid);
adapter = new DistrictOfficerGridAdapter(this, serialArrayList);
gridView.setAdapter(adapter);
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
startActivity(new Intent(getApplicationContext(), MemberDetailsActivity.class));
Intent in = new Intent(DistrictOfficerActivity.this, MemberDetailsActivity.class);
in.putExtra("name", serialArrayList.getTitle());
in.putExtra("desig", serialArrayList.getPosition());
in.putExtra("contact", serialArrayList.getMobile());
in.putExtra("addr", serialArrayList.getAddress());
in.putExtra("blood", serialArrayList.getBloodGroup());
in.putExtra("image",serialArrayList.getPhotos());
in.putExtra("email", serialArrayList.getEmail());
in.putExtra("desc", serialArrayList.getDesc());
in.putExtra("website", serialArrayList.getWebsite());
in.putExtra("land", serialArrayList.getLandline());
startActivity(in);
}
});
然后从MemberDetailsActivity
接收数据并按以下方式实现:
nam = getIntent().getStringExtra("name").toString();
design = getIntent().getStringExtra("desig");
contat = getIntent().getStringExtra("contact");
addr = getIntent().getStringExtra("addr");
blood = getIntent().getStringExtra("blood");
image = getIntent().getStringExtra("image");
website = getIntent().getStringExtra("website");
email = getIntent().getStringExtra("email");
landL = getIntent().getStringExtra("land");
name.setText(nam.toString());
desig.setText(design.toString());
phoneNumber.setText(contat.toString());
address.setText(addr.toString());
bloodG.setText(blood.toString());
Glide.with(getApplicationContext()).load(image).into(imag);
web.setText(website.toString());
emai.setText(email.toString());
landline.setText(landL.toString());
答案 0 :(得分:2)
您在这里犯了一个错误。您两次致电“活动”,因此请删除其中之一。试试这个
row_number()
答案 1 :(得分:1)
我希望这对您有用。
您两次开始活动。
startActivity(new Intent(getApplicationContext(), MemberDetailsActivity.class));
删除此行。每当您单击项目活动两次时,活动就会打开,这意味着您按下活动时会将活动添加到堆栈中,因此您没有从活动中获得意图,这就是为什么它会导致空指针异常。