-1

This is my activity:

        public class TopReviews extends AppCompatActivity {

            public static String[] item_name={"Shoes","Shirts","Jeans","T-Shirts","Suite"};
           // public static String[] item_quantity={"2","4","3","2","8"};
            public static String [] item_description ={"Aqwer tyuffds","ABCSas fdkdfjsd","JAVA 12345669sd","assdecd Jsp","Microsoft band kro .Net"};
            public static String [] item_username ={"Ali","Bashir","Ahsan","Abubakar","Shani"};



            ListView lv;
            Context context1;


            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_top_reviews);

                context1=this;

                lv=(ListView) findViewById(R.id.reviews_listview);

    **//I Always got the null point exception on the line below...**

                lv.setAdapter(new ReviewsAdapterForReviews(context1,item_name,item_name,item_name));

            }  
        }

This is my adapter class:

package com.app.beautysaloon;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.*;


public class ReviewsAdapterForReviews extends ArrayAdapter<String> {


    String[] i_name,i_username,i_description;
    LayoutInflater inflater;
    Context context123;
    public static Intent i;
    ViewHolder holder;
    public ReviewsAdapterForReviews(Context context, String[] item_name,String[]item_description,String[]item_username) {

        super(context, R.layout.activity_top_reviews,item_name
        );
        // TODO Auto-generated constructor stub
        context123=context;
        i_name=item_name;
        i_username=item_username;
        i_description=item_description;
    }
    public class ViewHolder {
        TextView item_name,item_description,item_username;
    }
    @Override
    public View getView(final int position, View convertView,
                        ViewGroup parent) {
        // TODO Auto-generated method stub

        if(convertView==null){
            inflater=LayoutInflater.from(context123);
            convertView=inflater.inflate
                    (R.layout.activity_top_reviews,null);
        }

        holder=new ViewHolder();

        holder.item_name=(TextView) convertView.findViewById
                (R.id.saloonname_tv);
        holder.item_description=(TextView) convertView.findViewById
                (R.id.reviews_description_tv);
        holder.item_username = (TextView) convertView.findViewById
                (R.id.username_tv);


        holder.item_name.setText(i_name[position]);
        holder.item_description.setText(i_description[position]);
        holder.item_username.setText(i_username[position]);

        return convertView;
    }
}

I am just trying to pass my static data to the list view of activity. so please help me to find out where is the null pointer exception is. I get these Text view with holder class and also pass same layouts in adapter class but it give null point exception on list view at where i call the function of adapter class.

litelite
  • 2,857
  • 4
  • 23
  • 33
Ali Waheed
  • 41
  • 7

1 Answers1

0

Most probably this call returns null:

findViewById(R.id.reviews_listview)

it means there is no such view.

Max Farsikov
  • 2,451
  • 19
  • 25