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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:56:45+00:00 2026-05-27T06:56:45+00:00

I have a class which extends ListActivity within I have all methods for managing

  • 0

I have a class which extends ListActivity within I have all methods for managing database items: insertItems(), getItems(), showItems(), etc. Everything works great when I populate this list view with items from the database. What I want to do, is to populate in the same way an another ListView from another activity but when I am trying to pass the cursor to that activity I get NullPointer Exception. I try to put what is most representative.

public class FOO extends ListActivity{
//...
public static DBAdapter items;
@override
public void onCreate(){
   //...
   items = new DBAdapter(this);
   //...
}
public static Cursor getAllItems() {
    // TODO Auto-generated method stub
    db = items.getReadableDatabase();
    return db.query(DBConstants.TABLE_NAME, FROM, null, null, null, null, null);
   }

then, in the second activity I have:

public class BAR extends ListActivity{
//.....
public FOO foo = new FOO();
Cursor cursor;
 //...
public static DBAdapter items;
@override
public void onCreate(){
   //...
   items = new DBAdapter(this);
   foo.insertItems(//arguments);
   this.cursor = foo.getAllItems();
   this.startManagingCursor(this.cursor);
   ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.item_list, cursor,     FROM, TO);
    setListAdapter(adapter);
}

What I get first is this error, where MainActivity = BAR

 E/AndroidRuntime(22923): java.lang.RuntimeException: Unable to start activity ComponentInfo{your.pack.databasae/your.pack.databasae.MainActivity}: java.lang.NullPointerException
  • 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-27T06:56:46+00:00Added an answer on May 27, 2026 at 6:56 am

    public FOO foo = new FOO();

    You should never be creating activities like this, its up to the framework to construct activities as needed. That said if you need to do it this way, make sure items and db are created in the constructor for FOO (typical code would have it get created in onCreate() which would lead to a NPE here). Nothing in BAR ever calls FOO’s onCreate so items and presumably db are both null.

    Alternatively, try to refactor your code such that the database management code is available in a separate class accessible from both ListActivity classes.

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

Sidebar

Related Questions

I have a main class which extends Activity which should spawn a ListActivity and
I have a custom class loader which extends from a URLClassLoader. I added a
I have a view in Eclipse (implemented by a class which extends org.eclipse.ui.part.ViewPart )
I have 2 web user controls, both inherit the same base class which extends
I have two Java classes: B, which extends another class A, as follows :
Suppose i have a class which extends ViewGroup public class MapView extends ViewGroup It
I have an activity which extends ListActivity. It has many things but amongst them
I have following code: public class ShowActivity extends ListActivity implements OnItemClickListener { /** Called
In the application I am writing, I have a main class which extends the
Summery of problem:- I have classes named AttachPicture which extends the ListActivity and another

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.