-1

I am sending the value from Activity A to Activity B and data is set to the view, it is working fine but when I press back button it is returning the nullpointerexpection in textView.setText() method . I have implemented as follows:

 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);

        }
    });

And the data is received from MemberDetailsActivity and implemented as follows:

    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());
olajide
  • 972
  • 1
  • 13
  • 26
Nabin Dhakal
  • 1,949
  • 3
  • 20
  • 48

2 Answers2

2

You do one mistake here. You are calling your Activity twice so please remove one of them. Try with this

gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        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);

    }
});
Akash
  • 961
  • 6
  • 15
1

I hope this will work for you.

You start activity two times.

 startActivity(new Intent(getApplicationContext(), MemberDetailsActivity.class));

remove this line. whenever you click on item activity opens two times that means activities are added into stack when you pressed back you did not get intent from activity that's why it is giving null pointer exception.

GParekar
  • 1,209
  • 1
  • 8
  • 15