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 8566443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:39:21+00:00 2026-06-11T17:39:21+00:00

I have a problem when I want to make custom listview in android. MyListView

  • 0

I have a problem when I want to make custom listview in android.

MyListView class :

public class MyListView extends ArrayAdapter<Quotes> {

    Context context;
    int resource ;
    private final List<Quotes> items;
    public MyListView(Context context,int resourse , List<Quotes> items){
        super(context, resourse,items);
        this.resource = resourse;
        this.items = items;
    }

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

    try {
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.list_item, null);
        }
        Quotes item = items.get(position);
        TextView text = (TextView) v.findViewById(R.id.listItemText);
        TextView id = (TextView) v.findViewById(R.id.listItemId);
        text.setText(item.getText());
        id.setText(item.getID());
    } catch (NullPointerException e) {
        e.printStackTrace();
        Log.e("Error Saeed", e.getMessage());
    }
    return convertView;
}


}

and in MainActivity in onCreate method :

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        DatabaseHandler db = new DatabaseHandler(this);
        final ListView lv = (ListView)findViewById(R.id.listView1);
        MyListView adapter = new MyListView(this, R.layout.list_item, db.getAllQuotes());
        lv.setAdapter(adapter);       
    }

DatabaseHander class

public class DatabaseHandler extends SQLiteOpenHelper {

....
....

        public List<Quotes> getAllQuotes(){
        SQLiteDatabase db = getWritableDatabase();
        Cursor c = db.rawQuery("select * from "+TABLE_QUOTE,null);
        List<Quotes> quotes = new ArrayList<Quotes>();
        if(c.moveToFirst()){
            do{
                Quotes q = new Quotes(Integer.parseInt(c.getString(0)),c.getString(1),c.getString(2));
                quotes.add(q);
            }while(c.moveToNext());
        }
        db.close();
        c.close();
        return quotes;
    }

...
...
}

when I run the app its get an error and close.

in this link you can see log.txt

where is the problem?

  • 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-11T17:39:22+00:00Added an answer on June 11, 2026 at 5:39 pm

    You probably have a NullPointerException because you don’t initialize the ViewHolder in the getView method when convertView is null:

    ViewHolder holder = null;
    Quotes item = items.get(position);
    if(convertView == null){
            convertView = inflater.inflate(R.layout.list_item, null);
            holder = new ViewHolder();
            holder.txtTitle = (TextView) convertView.findViewById(R.id.listItemText);
            holder.txtID = (TextView)convertView.findViewById(R.id.listItemId);
            convertView.setTag(holder); 
    } else {
            holder = (ViewHolder) convertView.getTag();
    }
    

    There could be other problems in your code.

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

Sidebar

Related Questions

I have 3 panels and I want to make drags on them. The problem
I have such a problem - I want to make spinner's scrollbar always visible.
I have a very precise question: I want to make an android application that
i have a table view that i want to make a custom uinavigationn bar
I have the following problem / bug: I made a custom button-class (called CustomBlitButton)
I have this problem: I want to generate a new source code file from
I am using GWT/JAVA for development. I have following problem: I want to remove
I have a problem and I want to implement the MVC pattern to my
I have a problem when I want to sending data using byte format in
I have problem, when I want add Node to my GUI from other Thread.

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.