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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:12:50+00:00 2026-05-26T19:12:50+00:00

right now I’m trying to open database, using db=SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY); Cursor resultset =

  • 0

right now I’m trying to open database, using

db=SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
        Cursor resultset = db.query("person_table", null, null, null, null, null, null);

so I’m using Cursor to get each of the result set return by the db query. Each of the result set return I add to the array to be view in the ListView. Below is my code for fetch data from db

package com.android.my.mypackage;

import android.app.ListActivity;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.Cursor;
import android.widget.ListView;
import java.util.ArrayList;
import java.util.List;

public class personDetail extends ListActivity{

    private static String DBPATH="data/data/com.android.my.mypackage/databases/";
    private static String DBNAME="persondb.db";
    private View refView;
    public ListView personlist;

    public personDetail(View v, ListView l){
        refView = v;
        personlist = l;
    }

    public void DisplayPersonDetail(){
        SQLiteDatabase db=null;
        String path=DBPATH+DBNAME;

        db=SQLiteDatabase.openDatabase(path, null, SQLiteDatabase.OPEN_READONLY);
        Cursor resultset = db.query("person_table", null, null, null, null, null, null);
        if(resultset.getCount()==0){            
            /*please ignore this block*/
        }else{
            resultset.moveToFirst();
            List<String> arl = new ArrayList<String>();         
            while(resultset.isAfterLast()==false){

                arl.add(resultset.getString(6).toString() + "@@" + resultset.getString(1).toString());                              
                resultset.moveToNext();                         
            }
            //Toast.makeText(refView.getContext(), "Arl value " + arl, Toast.LENGTH_LONG).show();
            personlist.setAdapter(new PersonAdapter(this, arl));
        }       
    }

}

And below is PersonAdapter class

package com.android.my.mypackage;

import java.util.List;
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.ImageView;


public class PersonAdapter extends ArrayAdapter<String>{
    private static Activity context;
    private final List<String> list;

    public PersonAdapter(Activity c, List<String> list){
        super(context, R.layout.person_adapter, list);
        this.context = c;
        this.list = list;
    }

    static class ViewHolder{
        private TextView descHolder;
        private ImageView typeHolder;
    }

    public View getView(int position, View convertview, ViewGroup group){

        ViewHolder holder;
        View lView = convertview;

        if(lView==null){
            LayoutInflater inf = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            lView = inf.inflate(R.layout.person_adapter, group, true);
            holder = new ViewHolder();
            holder.descHolder = (TextView) lView.findViewById(R.id.personDescLbl);
            holder.typeHolder = (ImageView) lView.findViewById(R.id.personCategoryImage);
        }else{
            holder = (ViewHolder) lView.getTag();
        }

        holder.descHolder.setText(list.get(position).toString().split("@@")[0]);
        String category = list.get(position).toString().split("@@")[1];
        if(category.equals("Male")){
            holder.typeHolder.setImageResource(R.drawable.male);
        }else{
            holder.typeHolder.setImageResource(R.drawable.female);
        }               
        return lView;
    }
}

and my person_adapter layout to inflate with list view

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <TextView 
        android:id="@+id/personDescLbl"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_vertical"/>
    <ImageView 
        android:id="@+id/personCategoryImage"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>       
</LinearLayout>

My code is based on tutorial from this site. But i get Nullpointer exception error in PersonAdapter class which is pointed to

super(context, R.layout.person_adapter, list);

Before this I display the result set using table layout and it”s working find. But it is not a good practicall using table layout to display large amount of data it as it counsume time and memory. So please help me accomplished the listView adapter. Thanks.

  • 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-26T19:12:51+00:00Added an answer on May 26, 2026 at 7:12 pm

    In your PersonAdapter, your context field is null when you call the super constructor.
    You only initialize it on the second line. Your should pass the activity as the first parameter of super (you called it c), and then affect your context field.

    public class PersonAdapter extends ArrayAdapter<String>{
        private static Activity context;
        ...
    
        public PersonAdapter(Activity c, List<String> list){
            super(c, R.layout.person_adapter, list);
            this.context = c;
            this.list = list;
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I have a database (about 2-3 GB) in PostgreSQL, which serves as
Right now, I have three models Post, Comment and User (using Devise ) associated
right now i m using adobe live media encoder to stream live webcam video
Right now I have a mysql database with a table userphone(id, phone, type,userid) and
Right now I am only trying to get my getline() function to work. I
Right now I am using learning to program for the iphone and I am
Right now we have a dll file that contains all the database calls and
Right now, I'm using this to allow a file to be moved to our
Right now I'm asking the user for two numbers. I'm trying to print the
right now I'm creating an array and using: render :json => @comments This would

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.