0

I have a button object that I want to make clickable and start a new Intent. The buttons layout just fine across the array list, but when I try and add the on click listenter, it comes up with the problem "Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference"

Here is my code:

public class PhotoshootAdapter extends ArrayAdapter{

    private List<Photoshoots> photoshootsscheduleList;
    private int resource;
    private LayoutInflater inflater;
    public PhotoshootAdapter(Context context, int resource, List<Photoshoots> objects) {
        super(context, resource, objects);
        photoshootsscheduleList = objects;
        this.resource = resource;
        inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {

            convertView = inflater.inflate(resource, null);
        }


        Button btnPhotoshoot;

        btnPhotoshoot = (Button)findViewById(R.id.btnPhotoshoot);


        TextView tvPotential;
        TextView tvAddress;
        TextView tvDateofShoot;




        tvPotential = (TextView) convertView.findViewById(R.id.tvPotential);
        tvAddress = (TextView) convertView.findViewById(R.id.tvAddress);
        tvDateofShoot = (TextView)convertView.findViewById(R.id.tvDateofShoot);

        StringBuffer potentialBuffer = new StringBuffer();
        for(Photoshoots.potentialDetails details : photoshootsscheduleList.get(position).getPotentialDetails()){
            potentialBuffer.append(details.getPotentialName() + "\n");
          }
        StringBuffer addressBuffer = new StringBuffer();
        for(Photoshoots.addressDetails details : photoshootsscheduleList.get(position).getAddressDetails()){
            addressBuffer.append(details.getAddress() + "\n");
        }
        StringBuffer dateBuffer = new StringBuffer();
        for(Photoshoots.dateDetails details : photoshootsscheduleList.get(position).getDateDetails()){
            dateBuffer.append(details.getDateofShoot());
        }
        final StringBuffer potentialIDBuffer = new StringBuffer();
        for(Photoshoots.PotentialIDDetails details : photoshootsscheduleList.get(position).getPotentialIDDetails()){
            potentialIDBuffer.append(details.getPotentialIDDetails());
        }


        tvPotential.setText(potentialBuffer.toString());
        tvAddress.setText(addressBuffer.toString());
        tvDateofShoot.setText(dateBuffer.toString());

        btnPhotoshoot.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            Intent intent = new Intent(ShowPhotoshootList.this, schedule_my_photoshoot.class);
                intent.putExtra("PotentialID", potentialIDBuffer.toString());

            }
        });


        return convertView;
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

0 Answers0