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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T15:39:52+00:00 2026-05-24T15:39:52+00:00

I have a superclass for my Activities (WhereWolfActivity) in my Android app that has

  • 0

I have a superclass for my Activities (WhereWolfActivity) in my Android app that has a static SQLiteDatabaseOpenHelper for all subclasses to use. The database connection is opened in onCreate and closed in onDestroy (I keep track of the number of subclass Activities open to ensure the database connection is only closed when the last Activity in the app is destroyed). When a user logs out, they are taken to a welcome screen Activity that does not subclass WhereWolfActivity, so the database connection is closed. However, the application Force Closes when the application logs out and I get the following logcat output:

08-11 02:28:24.858: ERROR/AndroidRuntime(29022): FATAL EXCEPTION: main
08-11 02:28:24.858: ERROR/AndroidRuntime(29022): java.lang.RuntimeException: Unable to destroy activity {uk.ac.ic.doc.vmw10.wherewolf/uk.ac.ic.doc.vmw10.wherewolf.activities.Tabs}: java.lang.NullPointerException
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3655)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3673)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at android.app.ActivityThread.access$2900(ActivityThread.java:125)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at android.os.Looper.loop(Looper.java:123)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at java.lang.reflect.Method.invokeNative(Native Method)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at java.lang.reflect.Method.invoke(Method.java:521)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at dalvik.system.NativeStart.main(Native Method)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022): Caused by: java.lang.NullPointerException
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at uk.ac.ic.doc.vmw10.wherewolf.activities.WhereWolfActivity.onDestroy(WhereWolfActivity.java:119)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3642)
08-11 02:28:24.858: ERROR/AndroidRuntime(29022):     ... 11 more

The NullPointerException occurs on the line that says: dbHelper.close();

Any idea why attempting to close the database would give a null pointer exception?

  • 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-24T15:39:53+00:00Added an answer on May 24, 2026 at 3:39 pm

    We can’t really know why without seeing your code, but apparently your dbHelper is null. This has nothing to do with trying to close it.

    On another note, make your life simpler and have a singleton class for your database. As for closing, you don’t really need to do this, just keep it open. When your process dies, that will take care of closing the database. Make sure you close all your cursors though.

    Something like:

    public class MyDbHelper extends SQLiteOpenHelper {
    
        private Context context;
    
        private static MyDbHelper instance;
    
        public static MyDbHelper getInstance(Context context) {
            if (instance == null) {
                instance = new MyDbHelper(context);
            }
    
            return instance;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an AbstractEntity class as superclass for all my entites that defines an
I have several classes, that all derives from SuperClass. When the classes are created,
I have a superclass of type Question which has multiple subclasses (e.g. MultipleChoiceQuestion and
I have an abstract superclass that has JPA annotations on it mapping some of
Think that I have many activities,and all I want is this: I have a
I have a superclass called Transaction that has a property named TransactionId. This property
If I have a superclass, say Animal , and two subclasses: Zebra and Giraffe
I have a table of electronic devices that serves as a generic superclass and
I have a subclass that calls a method from a superclass. The method in
Say I had a class SuperClass and two subclasses SubClassA and SubClassB that inherit

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.