Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8821909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:58:14+00:00 2026-06-14T05:58:14+00:00

I have a listView that is populated from a database wich has 22 items.

  • 0

I have a listView that is populated from a database wich has 22 items. All the items show up in the list when I bind the items from the database to my listView.

But here is the problem.. I can select only the top 7 items from the listView.
When I try to select the 8th – 22th item in the view I get a nullpointerException.

Does anyone know why and how I can fix this problem?

My code when selecting items in the list:

        listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
              //ListView lv = (ListView) arg0;
              TextView tv = (TextView) ((ListView) findViewById(R.id.list_view)).getChildAt(arg2);
              //error here \/
              if (tv == null) {
                  Log.v("TextView", "Null");
              }

              String s = tv.getText().toString();
              _listViewPostion = arg2;

              Toast.makeText(CustomerPick.this, "Du valde: " + s, arg2).show();
        }
    });

Code when Binding the values to listView:

    public ArrayAdapter<Customer> BindValues(Context context){
    ArrayAdapter<Customer> adapter = null;
    openDataBase(true);

    try{ 

        List<Customer> list = new ArrayList<Customer>(); 
        Cursor cursor = getCustomers();

        if (cursor.moveToFirst()) 
        {
            do 
            {  
                list.add(new Customer(cursor.getInt(0), cursor.getString(1)));   
            } 
            while (cursor.moveToNext());  
        } 
        _db.close();  
        Customer[] customers = (Customer []) list.toArray(new Customer[list.size()]);  
        Log.v("PO's",String.valueOf(customers.length));  


        adapter = new ArrayAdapter<Customer>(context, android.R.layout.simple_list_item_single_choice, customers);

        }  
        catch(Exception e)  
        {  
            Log.v("Error", e.toString());
        }  
        finally{
            close();
        }
    return adapter;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:58:15+00:00Added an answer on June 14, 2026 at 5:58 am

    You’re trying to get data from the listview elements directly which is never a good idea. You’re getting nulls cause there really is only 7 items on the screen. When you scroll, the seven items are rearranged with their data changed so that it seems like it’s scrolling, keeps things resource conscious. Listviews should be seen as only for viewing purposes. If you need data, refer to the data source via position or Id or otherwise, in this case your arraylist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView in my activity that is populated from a database Cursor
I have a listview that is being populated by information from a database using
I have a ListView in a ListFragment that is populated via a database query.
I have a ListView with custom adapter which is populated from local sqlite database.
I have a list of images that are pulled from a database and loaded
I have a list view which is populated via records from the database. Now
I have a listview which populates its content from SQLite Database. Here's my code:
I am using a listView that is being populated from a database. I know
I have a ListView that is populated with rows. These rows come from an
i have a listview that shows diferent data from my database. this works perfeclty.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.