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

  • Home
  • SEARCH
  • 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 6650247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:52:13+00:00 2026-05-26T00:52:13+00:00

Hy!! I have a listview that should be filled with data from the database

  • 0

Hy!!

I have a listview that should be filled with data from the database

Code:

private void onCreateDBAndDBTabled() {
        myDB = this.openOrCreateDatabase(MY_DB_NAME, MODE_PRIVATE, null);
        myDB.execSQL("CREATE TABLE IF NOT EXISTS " + MY_DB_TABLE
                + " (_id integer primary key autoincrement, name varchar(100), rate integer(1), eattime datetime)"
                +";");
    ArrayList<Pizza> list = new ArrayList<Pizza>();
Cursor cursor = this.myDB.query(MY_DB_TABLE, new String[] { "name" },null,null,null,null,null,null);
      if (cursor.moveToFirst()) {
         do {
             Log.e("XXX", "Courser Enter: " + cursor.getString(0));
             Pizza pizza = new Pizza();
             pizza.title= cursor.getString(0);
            list.add(pizza); 
            } 
         while (cursor.moveToNext());
      }
      if (cursor != null && !cursor.isClosed()) {
         cursor.close();
      }
      Log.e("XXX", "Count:" + list.size());
      Log.e("XXX", "Item[0] -->" +  list.toArray()[0].toString());
      CustomAdapter aa = new CustomAdapter(this, R.layout.customlistitem,list);
     Log.e("XXX", String.valueOf(aa.getCount()));
      lv.setAdapter(aa);
    }

Customadapter:

public class CustomAdapter extends ArrayAdapter<Pizza>{

    private ArrayList<Pizza> pizzen;

    public CustomAdapter(Context context, int textViewResourceId,ArrayList<Pizza> objects) {
        super(context, textViewResourceId, objects);
        this.pizzen = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = convertView;
        Pizza pizza = pizzen.get(position);
        if (v == null) {

        }

        return v;//super.getView(position, convertView, parent);


    }

Pizza:

public class Pizza{

    public String title;
    public int rate;
    public Date date;
}

Error:

09-30 08:58:38.661: ERROR/XXX(667): Courser Enter: EditText
09-30 08:58:38.671: ERROR/XXX(667): Count:1
09-30 08:58:38.671: ERROR/XXX(667): Item[0] -->com.korn.pizzacounter.Pizza@43b91850
09-30 08:58:38.671: ERROR/XXX(667): 1
09-30 08:58:38.751: ERROR/AndroidRuntime(667): Uncaught handler: thread main exiting due to uncaught exception
09-30 08:58:38.762: ERROR/AndroidRuntime(667): java.lang.NullPointerException
09-30 08:58:38.762: ERROR/AndroidRuntime(667):     at android.widget.AbsListView.obtainView(AbsListView.java:1276)
09-30 08:58:38.762: ERROR/AndroidRuntime(667):     at android.widget.ListView.makeAndAddView(ListView.java:1668)
09-30 08:58:38.762: ERROR/AndroidRuntime(667):     at android.widget.ListView.fillDown(ListView.java:637)
09-30 08:58:38.762: ERROR/AndroidRuntime(667):     at android.widget.ListView.fillFromTop(ListView.java:694)
09-30 08:58:38.762: ERROR/AndroidRuntime(667):     at android.widget.ListView.layoutChildren(ListView.java:1521)
09-30 08:58:38.762: ERROR/AndroidRuntime(667):     at android.widget.AbsListView.onLayout(AbsListView.java:1113)
09-30 08:58:38.762: ERROR/AndroidRuntime(667):     at android.view.View.layout(View.java:6830)

The error is a NullPoinerException although the ListSize is 1 (see the log)

  • 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-05-26T00:52:14+00:00Added an answer on May 26, 2026 at 12:52 am

    It’s because in your getView() method you are not inflating the convertView and it is returning you null.

    Your getView should be something like this inflating a row.xml which contains a TextView.

    @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
    
            TextView mTextView = null;
            if (convertView == null) {
                convertView = inflater.inflate(R.layout.row, parent, false);
                mTextView = (TextView) convertView.findViewById(R.id.txt_list);
                convertView.setTag(mTextView);
            }
            else{
                mTextView = (TextView) convertView.getTag();
            }
            mTextView.setText(arrList.get(position));
            return convertView;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listview that's populated by rows that get their data from a
I have a ListView that contains some data from sqllite table. the table is
I have a ListView in my activity that is populated from a database Cursor
I have a ListView and a Arrayadapter filled with Strings. The data should be
I have a ListView that I am populating with items from an ObservableCollection .
I have a 2X2 Grid that is filled with 2 Listview controls and some
I have a ListView that is displaying images downloaded from the internet. My UI
I have a listview that displays files from a directory. The user can drag
I have an onClickListener that should call a class that shows and image from
I have a listview that you select a row/item on. This is linked to

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.