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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:45:31+00:00 2026-06-19T02:45:31+00:00

i am using custom cursor adapter to get catagories in listview from SQlite view

  • 0

i am using custom cursor adapter to get catagories in listview from SQlite view and also want to show specific rows count saved with same category name.i try many times but unfortuntely can’t succeed.

here the Query which i used

int GetTasksCountByCategory(String cat)
 {

     Cursor cur = mDb.rawQuery(" SELECT Count(*) FROM  ViewTasks where Category_name = "+"'"+"cat"+"'", null);
     int x = 0;
     if (cur.moveToFirst())
     {
         x = cur.getInt(0);
     }

        cur.close();
        return x;    
 }

and my Adapter class

public class cursorAdapter2 extends CursorAdapter{
    private Context mContext;
    DbAdapter myAdapter = new DbAdapter(mContext);

    @SuppressWarnings("deprecation")
    public cursorAdapter2(Context context, Cursor c) {
        super(context, c);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    @Override
    public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
        // TODO Auto-generated method stub
         LayoutInflater inflater = LayoutInflater.from(arg2.getContext());
         View retView = inflater.inflate(R.layout.list, arg2, false);

        return retView;
    }

    @SuppressWarnings("unused")
    @Override
    public void bindView(View view, Context arg1, Cursor cursor) {
        // TODO Auto-generated method stub
        TextView category = (TextView) view.findViewById(R.id.txtLastcatId);
        category.setText(cursor.getString(cursor.getColumnIndex(DbAdapter.KEY_CATEGORY_NAME)));

         String getCat = (String) category.getText();
           int i = myAdapter.GetTasksCountByCategory(getCat);
        Button count = (Button) view.findViewById(R.id.button2);
        count.setText(Integer.toString(i));

        Button img = (Button) view.findViewById(R.id.button1);
    }

}

in this i get null pointer exception
anyone plz help me
thanx in advance

  • 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-19T02:45:32+00:00Added an answer on June 19, 2026 at 2:45 am

    two things. first the assignment of DbAdapter myAdapter should be done in the class’ constructor…when mContext has a value.

    public cursorAdapter2(Context context, Cursor c) {
        super(context, c);
        mContext=context;
        myAdapter = new DbAdapter(mContext);
    }
    

    secondly modify the query from….

    Cursor cur = mDb.rawQuery(" SELECT Count(*) FROM  ViewTasks where Category_name = "+"'"+"cat"+"'", null);
    

    to

    Cursor cur = mDb.rawQuery("SELECT Count(*) FROM ViewTasks where Category_name = ?", new String[] { cat } );
    

    you are passing in the string "cat" not the variable cat.

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

Sidebar

Related Questions

I'm using cursor adapter to get a custom list view.I've two xml files. a.xml
I am reading from a database into a listview using a custom cursor adapter.
I have a custom cursor adapter I'm using to fill a ListView. The inflater
I'm using a custom list adapter for my ListView. How can I get the
I am using a custom Adapter class. And retrieving data from database using cursor.
i m using simple cursor adapter to fetch all records from a view in
i am using custom checkbox buttons in my table view and want to save
i have a listview with checkbox in each rows. i'm using custom cursoradapter and
I have a listview with custom adapter which displays names from the contacts .
I need a little help with my custom list view adapter. I'm using the

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.