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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:33:17+00:00 2026-06-16T17:33:17+00:00

I keep getting a Fatal java.lang.IllegalStateException error when I start up my app and

  • 0

I keep getting a Fatal java.lang.IllegalStateException error when I start up my app and I’m not sure why. Basically all I’m trying to do is return the running processes and tasks every 10 seconds.

Here’s my code:

public class MainActivity extends Activity {

    Handler h = new Handler();
    public static final String TAG = "MyActivity";
    int s;

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

    public void Checker() {
        Handler h = new Handler();
        h.post(check);
    }

    Runnable check = new Runnable() {
        ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        public void run() {
            Processes(am);
            Tasks(am);
            h.postAtTime(check, 10000);
        }
    };

    public void Processes(ActivityManager am) {
        List<ActivityManager.RunningAppProcessInfo> l = am.getRunningAppProcesses();
        s = l.size();
        for(int i = 0; i < s; i++) {
            Log.d(TAG, "Process:  " + l.get(i).processName);
        }
    }

    public void Tasks(ActivityManager am) {
        List<ActivityManager.RunningTaskInfo> l = am.getRunningTasks(1000);
        s = l.size();
        for(int i = 0; i < s; i++) {
            // .baseActivity returns the process that started the Task
            Log.d(TAG, "Task:  " + l.get(i).baseActivity.getPackageName());
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

And here are my logs:

12-18 08:03:53.190: E/AndroidRuntime(1577): FATAL EXCEPTION: main
12-18 08:03:53.190: E/AndroidRuntime(1577): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.androidside/com.example.androidside.MainActivity}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.os.Looper.loop(Looper.java:137)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.ActivityThread.main(ActivityThread.java:5039)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at java.lang.reflect.Method.invokeNative(Native Method)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at java.lang.reflect.Method.invoke(Method.java:511)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at dalvik.system.NativeStart.main(Native Method)
12-18 08:03:53.190: E/AndroidRuntime(1577): Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.Activity.getSystemService(Activity.java:4463)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at com.example.androidside.MainActivity$1.<init>(MainActivity.java:54)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at com.example.androidside.MainActivity.<init>(MainActivity.java:53)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at java.lang.Class.newInstanceImpl(Native Method)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at java.lang.Class.newInstance(Class.java:1319)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
12-18 08:03:53.190: E/AndroidRuntime(1577):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
12-18 08:03:53.190: E/AndroidRuntime(1577):     ... 11 more

Thanks for the help.

  • 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-16T17:33:19+00:00Added an answer on June 16, 2026 at 5:33 pm

    Try to change your code

    Handler h ;
        @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                h = new Handler();
                Checker();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Keep getting this error after inserting a subdatasheet into a query and trying to
Keep getting the error Arguments are not sufficiently instantiated for the multiplication by addition
I keep getting an error saying that @android:style/Widget.Holo.Light.Button.Borderless is not public and so can't
i keep getting a sytax error when trying to add (function (e) { e.preventDefault;
I have PEAR, MDB2 and Mysql Driver installed however I keep getting: Fatal error:
In the app I'm developing on Android, I keep getting a Fatal Signal 11
When I use this statement if(count($this->input->post('p_id') =0)) , I keep getting this error: Fatal
I am keep getting an error on my Code. I am trying to call
I keep getting Fatal error: Call to a member function prepare() on a non-object
i keep getting error : fatal error: mpi.h: No such file or directory how

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.