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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:45:17+00:00 2026-06-13T23:45:17+00:00

Possible Duplicate: System services not available to Activities before onCreate? I am trying to

  • 0

Possible Duplicate:
System services not available to Activities before onCreate?

I am trying to return the values of a database to a listview but I am getting an error. I am using a cursor to get the data from a table and a SimpleCursorAdapter to read the cursor. This is the method that does this:

public void getData(){
        String[] columns = new String[] {ModuleDB.KEY_ROWID, 
                ModuleDB.KEY_MODCODE,
                ModuleDB.KEY_MODNAME,
                ModuleDB.KEY_LECPRAC,
                ModuleDB.KEY_DAYS,
                ModuleDB.KEY_TIMESTART,
                ModuleDB.KEY_TIMEEND,
                ModuleDB.KEY_LOCATION,
                ModuleDB.KEY_INFO};
        int[] to = new int[]{R.id.modcode_entry,
                             R.id.modname_entry,
                             R.id.modlecprac_entry,
                             R.id.modday_entry,
                             R.id.modtimestart_entry,
                             R.id.modtimeend_entry,
                             R.id.modlocation_entry,
                             R.id.modaddinfo_entry};

        Cursor curs = myDatabase.query(ModuleDB.DB_TABLE, columns, null, null, null, null, null);
        if (curs != null)
            curs.moveToFirst();

        SimpleCursorAdapter dataSource = new SimpleCursorAdapter(ModuleDataSource.this, R.layout.list_entry, curs, columns, to);
        this.setListAdapter(dataSource);

        // Make sure to close the cursor
        curs.close();
        }

This method is causing the exception: "System Services not available to activites before onCreate()"

Can anyone help me with this? I can’t find any good tutorials for cursors and cursoradapters and I really am completely lost

EDIT:

This might help.

MainActivity.java

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ModuleDataSource dbinfo = new ModuleDataSource(this);
        dbinfo.open();
        dbinfo.getData();
        dbinfo.close();
    }

ModuleDataSource.java

public class ModuleDataSource extends ListActivity{

    private SQLiteDatabase myDatabase;
    private ModuleDB myhelper;

    public ModuleDataSource(Context context){
        myhelper = new ModuleDB(context);
    }

    public void open() throws SQLException { //Open the database for writing
        myDatabase = myhelper.getWritableDatabase();
    }

    public void close(){ //Close the database
        myhelper.close();
    }

    public void getData(){
        String[] columns = new String[] {ModuleDB.KEY_ROWID, 
                ModuleDB.KEY_MODCODE,
                ModuleDB.KEY_MODNAME,
                ModuleDB.KEY_LECPRAC,
                ModuleDB.KEY_DAYS,
                ModuleDB.KEY_TIMESTART,
                ModuleDB.KEY_TIMEEND,
                ModuleDB.KEY_LOCATION,
                ModuleDB.KEY_INFO};
        int[] to = new int[]{R.id.modcode_entry,
                             R.id.modname_entry,
                             R.id.modlecprac_entry,
                             R.id.modday_entry,
                             R.id.modtimestart_entry,
                             R.id.modtimeend_entry,
                             R.id.modlocation_entry,
                             R.id.modaddinfo_entry};

        Cursor curs = myDatabase.query(ModuleDB.DB_TABLE, columns, null, null, null, null, null);
        startManagingCursor(curs);

        if (curs != null)
            curs.moveToFirst();

        SimpleCursorAdapter dataSource = new SimpleCursorAdapter(ModuleDataSource.this, R.layout.list_entry, curs, columns, to);
        setListAdapter(dataSource);

        }
}

EDIT2: Logcat

11-06 23:24:07.885: D/AndroidRuntime(887): Shutting down VM
11-06 23:24:07.885: W/dalvikvm(887): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-06 23:24:07.895: E/AndroidRuntime(887): FATAL EXCEPTION: main
11-06 23:24:07.895: E/AndroidRuntime(887): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.adoherty.assignment3/com.adoherty.assignment3.MainActivity}: 
                                          java.lang.IllegalStateException: System services not available to Activities before onCreate()
11-06 23:24:07.895: E/AndroidRuntime(887):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-06 23:24:07.895: E/AndroidRuntime(887):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
11-06 23:24:07.895: E/AndroidRuntime(887):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
11-06 23:24:07.895: E/AndroidRuntime(887):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
11-06 23:24:07.895: E/AndroidRuntime(887):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-06 23:24:07.895: E/AndroidRuntime(887):  at android.os.Looper.loop(Looper.java:123)
11-06 23:24:07.895: E/AndroidRuntime(887):  at android.app.ActivityThread.main(ActivityThread.java:4627)
11-06 23:24:07.895: E/AndroidRuntime(887):  at java.lang.reflect.Method.invokeNative(Native Method)
11-06 23:24:07.895: E/AndroidRuntime(887):  at java.lang.reflect.Method.invoke(Method.java:521)
11-06 23:24:07.895: E/AndroidRuntime(887):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-06 23:24:07.895: E/AndroidRuntime(887):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-06 23:24:07.895: E/AndroidRuntime(887):  at dalvik.system.NativeStart.main(Native Method)
11-06 23:24:07.895: E/AndroidRuntime(887): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
11-06 23:24:07.895: E/AndroidRuntime(887):  at android.app.Activity.getSystemService(Activity.java:3526)
11-06 23:24:07.895: E/AndroidRuntime(887):  at android.widget.ResourceCursorAdapter.<init>(ResourceCursorAdapter.java:49)
11-06 23:24:07.895: E/AndroidRuntime(887):  at android.widget.SimpleCursorAdapter.<init>(SimpleCursorAdapter.java:84)
11-06 23:24:07.895: E/AndroidRuntime(887):  at com.adoherty.assignment3.ModuleDataSource.getData(ModuleDataSource.java:74)
11-06 23:24:07.895: E/AndroidRuntime(887):  at com.adoherty.assignment3.MainActivity.onCreate(MainActivity.java:17)
11-06 23:24:07.895: E/AndroidRuntime(887):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-06 23:24:07.895: E/AndroidRuntime(887):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-06 23:24:07.895: E/AndroidRuntime(887):  ... 11 more
  • 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-13T23:45:18+00:00Added an answer on June 13, 2026 at 11:45 pm

    ModuleDataSource extends ListActivity.. you are creating an instance of that within your Activity.. You cannot instantiate an activity as an object like that

    Your ListActivity is likely trying to make some system call that it normally makes in the background automatically for you. Since you are trying to instantiate a ListActivity as an object, the normal Activity process is not happening…

    You should move what you have in the ListActivity into your main activity and make your main activity the ListActivity

    Something like this:

    public class MainActivity extends ListActivity {
    
        private SQLiteDatabase myDatabase;
        private ModuleDB myhelper;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            myhelper = new ModuleDB(this);
            open();
            getData();
            close();
        }
    
        public void open() throws SQLException { //Open the database for writing
            myDatabase = myhelper.getWritableDatabase();
        }
    
        public void close(){ //Close the database
            myhelper.close();
        }
    
        public void getData(){
            String[] columns = new String[] {ModuleDB.KEY_ROWID, 
                    ModuleDB.KEY_MODCODE,
                    ModuleDB.KEY_MODNAME,
                    ModuleDB.KEY_LECPRAC,
                    ModuleDB.KEY_DAYS,
                    ModuleDB.KEY_TIMESTART,
                    ModuleDB.KEY_TIMEEND,
                    ModuleDB.KEY_LOCATION,
                    ModuleDB.KEY_INFO};
            int[] to = new int[]{R.id.modcode_entry,
                                 R.id.modname_entry,
                                 R.id.modlecprac_entry,
                                 R.id.modday_entry,
                                 R.id.modtimestart_entry,
                                 R.id.modtimeend_entry,
                                 R.id.modlocation_entry,
                                 R.id.modaddinfo_entry};
    
            Cursor curs = myDatabase.query(ModuleDB.DB_TABLE, columns, null, null, null, null, null);
            startManagingCursor(curs);
    
            SimpleCursorAdapter dataSource = new SimpleCursorAdapter(ModuleDataSource.this, R.layout.list_entry, curs, columns, to);
            setListAdapter(dataSource);
    
            }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What is System.Void? Why not System.Void? I noticed that it is not
Possible Duplicate: class System.Random .. why not static? Following on from Generated random numbers
Possible Duplicate: Why might a System.String object not cache its hash code? I always
Possible Duplicate: How can I return system information in Python? For example, to see
Possible Duplicate: System.BadImageFormatException invalid format when trying to install service with installutil.exe When I
Possible Duplicate: Rating System in PHP and MySQL I am working on a rating
Possible Duplicate: Writing a Windows system tray application with .NET I want to develop
Possible Duplicate: how do I add windows phone system colors to icon using expression
Possible Duplicate: Why should I use templating system in PHP? I was just curious
Possible Duplicate: How to invalidate the file system cache? In order to be able

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.