I’m trying to pass ArrayList of numbers to a textView in ArrayAdapter, but the app goes not responding

Here in MainActivity.java, i have created a ArrayList which has integer stored into it. When the app is run, it immediately stops responding. Dont know where I’m doing mistake and has a doubt whether TextView doesnt display integer directly.


     public class MainActivity extends AppCompatActivity {
        protected void onCreate(Bundle savedInstanceState) {
            ArrayList<Numbers> numbers = new ArrayList<>();
            numbers.add(new Numbers(1));
            numbers.add(new Numbers(2));
            numbers.add(new Numbers(3));
            numbers.add(new Numbers(4));
            numbers.add(new Numbers(5));
            numbers.add(new Numbers(6));
            numbers.add(new Numbers(7));
            NumberAdapter numberAdapter = new NumberAdapter(MainActivity.this, numbers);
            ListView listView = (ListView) findViewById(R.id.listview_flavor);

NumbersAdapter: public class NumberAdapter extends ArrayAdapter {

        public NumberAdapter(Activity context, ArrayList<Numbers> numbers) {

            super(context, 0, numbers);

        public View getView(int position, View convertView, ViewGroup parent) {
            // Check if the existing view is being reused, otherwise inflate the view
            View listItemView = convertView;
            if(listItemView == null) {
                listItemView = LayoutInflater.from(getContext()).inflate(
                        R.layout.list_item, parent, false);
            Numbers currentNumber = getItem(position);
            TextView nameTextView = (TextView) listItemView.findViewById(R.id.version_name);

            return listItemView;



You are setting integer value on Textview which is wrong you have to set string value please replace




Leave a Reply

Your email address will not be published. Required fields are marked *