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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:57:01+00:00 2026-06-13T14:57:01+00:00

I know how to do SQLite Database, when doing it specifically in its own

  • 0

I know how to do SQLite Database, when doing it specifically in its own dedicated java class. But whenever i want it to be inside of something, in this case, an Intent Service, it always give me errors, and i can’t debug it.

package my.skul;


    import android.app.IntentService;
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.app.PendingIntent;
    import android.content.Context;
    import android.content.Intent;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;

    public class CheckClassroom extends IntentService {

                /**
                 * A constructor is required, and must call the super IntentService(String)
                 * constructor with a name for the worker thread.
                 */
                public CheckClassroom() {
                    super("CheckClassroom");
                }

                /**
                 * The IntentService calls this method from the default worker thread with
                 * the intent that started the service. When this method returns,
                 * IntentService stops the service, as appropriate.
                 */
                @Override
                protected void onHandleIntent(Intent intent) {





                }
                private DbHelper ourHelper;
                private final Context ourContext;
                private SQLiteDatabase ourDatabase;

                private static class DbHelper extends SQLiteOpenHelper {

                    public DbHelper(Context context) {
                        super(context, "myschool", null, 1);
                        // TODO Auto-generated constructor stub
                    }

                    @Override
                    public void onCreate(SQLiteDatabase arg0) {
                        // TODO Auto-generated method stub

                    }

                    @Override
                    public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
                        // TODO Auto-generated method stub

                    }

                    public CheckClassroom(Context c) {
                        ourContext = c;
                    }

                    public CheckClassroom open() {
                        ourHelper = new DbHelper(ourContext);
                        ourDatabase = ourHelper.getWritableDatabase();

                        return this;

                    }

                    public void close() {
                        ourHelper.close();
                    }

            }
                getColumns()
                {
                    //retrieve sqlitedatabase data

                }


    }

I’ve been reading a lot about constructor, but i can’t really fully understand it, explaining all my errors here would really give me a better understanding of this. 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-06-13T14:57:01+00:00Added an answer on June 13, 2026 at 2:57 pm

    when i hover in public CheckClassroom() { super(“CheckClassroom”);
    }The blank final field ourContext may not have been initialized

    Because you declared the DbHelper class static, it will create an instance as soon as the CheckClassroom is instantiated. At that time, ourContext is still not initialized.

    To fix this, remove the static for the DbHelper class and make one instance to be a static field instead. Then in the constructor you can initialize that (after you initialize ourContext).

    private static DbHelper myDbHelper;
    
    public CheckClassroom() {
        super("CheckClassroom");
        ourContext = this;
        myDbHelper = new DbHelper();
    }
    

    And instead of using ourContext, you can just use CheckClassroom.this in the DbHelper class.

    Also…

    The public CheckClassroom(Context c) { ourContext = c; } function has nothing to do inside the DbHelper class….

    Also that open and close functions do not seem right, instead I think you should override onCreate and onDestroy

    Here is your code, fixed:

    package my.skul;
    
    import android.app.IntentService;
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.app.PendingIntent;
    import android.content.Context;
    import android.content.Intent;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;
    import android.database.sqlite.SQLiteOpenHelper;
    
    public class CheckClassroom extends IntentService {
    
                /**
                 * A constructor is required, and must call the super IntentService(String)
                 * constructor with a name for the worker thread.
                 */
                public CheckClassroom() {
                    super("CheckClassroom");
                }
    
                /**
                 * The IntentService calls this method from the default worker thread with
                 * the intent that started the service. When this method returns,
                 * IntentService stops the service, as appropriate.
                 */
                @Override
                protected void onHandleIntent(Intent intent) {
    
    
    
    
    
                }
                private DbHelper ourHelper;
                private SQLiteDatabase ourDatabase;
    
                @Override
                public void onCreate() {
                    ourHelper = new DbHelper();
                    ourDatabase = ourHelper.getWritableDatabase();
                }
    
                @Override
                public void onDestroy() {
                    ourHelper.close();
                }
    
                private class DbHelper extends SQLiteOpenHelper {
    
                    public DbHelper() {
                        super(CheckClassroom.this, "myschool", null, 1);
                        // TODO Auto-generated constructor stub
                    }
    
                    @Override
                    public void onCreate(SQLiteDatabase arg0) {
                        // TODO Auto-generated method stub
    
                    }
    
                    @Override
                    public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
                        // TODO Auto-generated method stub
    
                    }
                }
                /* not sure what that is... 
                getColumns()
                {
                    //retrieve sqlitedatabase data
    
                }
                */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is about Android and SQLite database. Simply, I want to know, how can
Please let me know how to delete n-rows in android sqlite database. I used
I know PHP 5 already supports SQLite but for some reason I can't get
My SQLite database is missing a column which I know exists. I will not
I followed instructions on http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/ and succesfully inserted sqlite database on android device so
I am doing a Bible application ,i have a default Bible database english DB.Sqlite,the
What am i doing? I am exporting my sqlite database into a csv --
Does someone know of a Sqlite manager that I can put on my site,
Anyone know why Subsonic 2.2 uses System.Data.SQLite version 1.0.60.0 instead of the latest version
I am newbie to SQLite and I don't know how to sort by fields.

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.