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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:20:51+00:00 2026-05-27T22:20:51+00:00

Error Unable to start activity ComponentInfo: java.lang.IllegalStateException: System services not available to Activities before

  • 0

Error Unable to start activity ComponentInfo: java.lang.IllegalStateException: System services not available to Activities before onCreate()

I´m experimenting with seperating the code and the use of a helper class. (Created different Java files)
What I did is created an Activity Java file that is registred in the Manifest and I didn´t register this following class (Java file):

import android.app.Activity;
import android.location.LocationManager;
import android.net.ConnectivityManager;
....


public class DeviceMonitor extends Activity {

    boolean laag=false;
    int level=-1;
    double batterylevel=-1;


    public boolean GPSEnabled() {

    final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) { // NO GPS ENABLED
        //ErrorMessage.append(R.string.enablegps);
        //ErrorMessage.append("\n");
        Log.d("StartPrepare","GPS DISABLED");
        return false;
                    } else {
        Log.d("StartPrepare","GPS ENABLED");
        return true;
                    }
    }

I removed the OnCreate() method, is this correct?
Should I have registred in the Manifest, if yes, how?

I received the following error while calling from the registred Activity like this:

DeviceMonitor MyDevice = new DeviceMonitor();
if (MyDevice.GPSEnabled()){gpsenabled=true;}else{gpsenabled=false;fout=true;}

Error:

E/AndroidRuntime(1912): java.lang.RuntimeException: Unable to start
activity
ComponentInfo{package}:
java.lang.IllegalStateException: System services not available to
Activities before onCreate()

Anybody that can give me some light on the helper classes (I´m kind of new in Java/Android) and has any clue what the error can cause? I tried to add the OnCreate() method, but it didn´t help.

Thanks a lot!

  • 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-27T22:20:52+00:00Added an answer on May 27, 2026 at 10:20 pm

    Do NOT do this…

    DeviceMonitor MyDevice = new DeviceMonitor();
    

    DeviceMonitor extends Activity and you should never create an instance of an Activity using new. An Android Activity is a special-case class and shouldn’t be treated like a normal Java class.

    If you want to start an Activity you need to do it using startActivity...) or one of the other ‘start’ methods.

    If you want a ‘helper’ class just create a standard Java class which doesn’t extend anything. When you create an instance of it from your main Activity, pass the Activity Context to it in its constructor then use that to access Android services etc. Example…

    public class DeviceMonitor {
    
        Context mContext = null;
    
        public DeviceMonitor (Context context) {
            mContext = context;
        }
    }
    

    EDIT: To create your helper and pass a Context from your main Activity do this…

    // An Activity IS a Context so pass 'this'
    DeviceMonitor MyDevice = new DeviceMonitor(this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Logcat 08-17 06:37:22.264: ERROR/AndroidRuntime(1090): java.lang.RuntimeException: Unable to start activity ComponentInfo{one.two/one.two.Booking}: java.lang.NullPointerException 08-17 06:37:22.264: ERROR/AndroidRuntime(1090):
What causing this Android RuntimeException? 02-01 15:13:41.316: ERROR/AndroidRuntime(3989): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.cccc.xxxx/com.cccc.xxxx.ActivityMyScreen}:
12-19 18:29:33.203: ERROR/AndroidRuntime(402): FATAL EXCEPTION: main 12-19 18:29:33.203: ERROR/AndroidRuntime(402): java.lang.RuntimeException: Unable to start activity
i am getting java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fb.test/com.fb.test.Fb_testActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x7f020005 error
the error in my logcat is such Logcat 08-29 08:20:57.961: ERROR/AndroidRuntime(1766): java.lang.RuntimeException: Unable to
java.lang.IllegalArgumentException: column 'data3' does not exist whats with data3 column?? LogCat 03-24 07:05:36.091: ERROR/AndroidRuntime(2540):
While running the application I'm getting these errors 10-09 10:20:57.138: ERROR/AndroidRuntime(282): java.lang.RuntimeException: Unable to
The logcat error: 08-24 11:16:19.760: ERROR/AndroidRuntime(6254): FATAL EXCEPTION: main 08-24 11:16:19.760: ERROR/AndroidRuntime(6254): java.lang.RuntimeException: Unable
How to solved error Unable to cast object of type 'System.Int32' to type 'Microsoft.DirectX.Direct3D.VertexShader'
Error: Unable to read data from the transport connection: A blocking operation was interrupted

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.