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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:10:34+00:00 2026-06-15T07:10:34+00:00

I want to pass data from my database DatabaseBon to a ListView . I

  • 0

I want to pass data from my database DatabaseBon to a ListView. I want to do this without using a ListViewActivity.

I have found out that I should use cursorAdapter for this, but is there some other way(without ListViewActivity)? I implemented CursorAdapter but got a Null Pointer Exception.

My Activity looks like:

      public class BlackNumbersBlockDb extends Activity {
        String TAG;
       @Override
   protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.blocknumbersdb);
    @SuppressWarnings("unused")
    Button imBT= (Button)findViewById(R.id.importBL);
    DataBaseBON info= new DataBaseBON(this);
    info.open();
    Cursor cursor=info.getcursor();
    startManagingCursor(cursor);
    ContactCursorAdapter adapter = new ContactCursorAdapter(null, cursor);
    ListView contactLV = (ListView) findViewById(R.id.listviewblDB);
    contactLV.setAdapter(adapter);
    info.close();
        imBT.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i= new Intent ("android.intent.action.IMPORTM");
            startActivity(i);   
        }
    });

My cursoradapter looks like:

            import vahid.engineer.com.DataBaseBON
            import android.content.Context;
            import android.database.Cursor;
            import android.view.LayoutInflater;
    public class ContactCursorAdapter extends CursorAdapter  {
  public ContactCursorAdapter(Context context, Cursor c) {  
    super(context, c);
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
    TextView name = (TextView)view.findViewById(R.id.blacklistDB1);
    name.setText(cursor.getString(cursor.getColumnIndex(DataBaseBON.N_NAME)));
    TextView phone = (TextView)view.findViewById(R.id.blacklistDB2); 
    phone.setText(cursor.getString(cursor.getColumnIndex(DataBaseBON.KEY_NUMBER)));}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    LayoutInflater inflater = LayoutInflater.from(context);
    View v = inflater.inflate(R.layout.lv, parent, false);
    bindView(v, context, cursor);
    return v;

My Xml File (block or not) is looks like

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >

  <ListView
      android:id="@+id/listviewblDB"
      android:layout_width="match_parent"
      android:layout_height="499dp"
      android:layout_weight="0.72" >
  </ListView>

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="129dp"
    android:gravity="bottom|center_horizontal|fill|top"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/importBL"
        android:layout_width="100dp"
        android:layout_height="90dp"
        android:layout_marginLeft="10sp"
        android:layout_marginTop="20sp"
        android:ems="10"
        android:text="Import"
        android:textSize="20sp"/>

    </LinearLayout>

My xml file LV looks like :

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical" >

  <TextView
          android:id="@+id/blacklistDB1"
          android:layout_width="33dp"
          android:layout_height="wrap_content"
          android:text="Large Text"
          />
   <TextView
        android:id="@+id/blacklistDB2"
        android:layout_width="19dp"
        android:layout_height="wrap_content"
        android:text="Large Text"
        />
   </LinearLayout>

My errors looks like

    FATAL EXCEPTION: main
    java.lang.NullPointerException
at android.view.LayoutInflater.from(LayoutInflater.java:171)
at vahid.engineer.com.ContactCursorAdapter.newView
at android.widget.CursorAdapter.getView(CursorAdapter.java:182)
at android.widget.AbsListView.obtainView(AbsListView.java:1315)
at android.widget.ListView.makeAndAddView(ListView.java:1727)
    at android.widget.ListView.fillDown(ListView.java:652)
at android.widget.ListView.fillFromTop(ListView.java:709)
at android.widget.ListView.layoutChildren(ListView.java:1580)
at android.widget.AbsListView.onLayout(AbsListView.java:1147)
at android.view.View.layout(View.java:7035)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:
at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
at android.view.View.layout(View.java:7035)
  • 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-15T07:10:36+00:00Added an answer on June 15, 2026 at 7:10 am
    ContactCursorAdapter adapter = new ContactCursorAdapter(null, cursor);
    

    that looks it’d have something to do with it. that parameter calls for your activity’s context, not null. You did it well for your database instantiation. The following should work.

    ContactCursorAdapter adapter = new ContactCursorAdapter(BlackNumbersBlockDb.this, cursor);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some text data from database that I want to display it on
I want to pass data from database to JSF page as a table. I
I want to pass data from second tab to first tab using delegates.But delegate
i have two flex applications and i want to pass the data from one
I have a PHP server script that SELECTs some data from a MySQL database.
I have some data from database coming out in a loop. Each of these
I written a program to retrieve data from database in servlets.now I want pass
I want to build a service that will pass the data read from the
I have a master page that needs to display some data from my database.
I have a listview in which i am binding data from database. i have

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.