The full error log is as follows:
FATAL EXCEPTION: main
Process: com.example.administrator.followview, PID: 8587
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.administrator.followview/com.example.administrator.followview.MainActivity}: java.lang.IllegalStateException: System services not available to Activities before onCreate()
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: java.lang.IllegalStateException: System services not available to Activities before onCreate()
at android.app.Activity.getSystemService(Activity.java:5253)
at com.example.administrator.followview.MainActivity.<init>(MainActivity.java:18)
at java.lang.Class.newInstance(Native Method)
at android.app.Instrumentation.newActivity(Instrumentation.java:1067)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2317)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
The error code is as follows:
public class MainActivity extends Activity implements View.OnTouchListener {
private Button mButton;
private ViewGroup mViewGroup;
private int xDelta;
private int yDelta;
WindowManager wm = (WindowManager) this
.getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
int height = wm.getDefaultDisplay().getHeight();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mViewGroup = (ViewGroup) findViewById(R.id.root);
Sure enough, it’s written on oncreate. Just put it into the oncreate method to run.
Read More:
- java.lang.IllegalStateException: Could not execute method for android:onClick
- [unity] Android package error java.lang.ClassNotFoundException Did not find class com.unity3d . player.MainActivity
- android Caused by: java.util.ConcurrentModificationException
- Spring boot running appears java.lang.IllegalStateException : Failed to load ApplicationContext
- java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
- Android 9.0 APP Install Android 4.4 Error: classnotfoundexception
- java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @Context
- Idea start error: java.lang.IllegalStateException : failed to create a child event loop
- java.lang.IllegalStateException : unable to read meta data for class
- java.lang.IllegalStateException Exception: cause analysis and solution
- Android appears java.lang.NoClassDefFoundError A solution to the error
- java.lang.IllegalStateException: Logback configuration error detected
- java.lang.IllegalStateException: Cannot call sendRedirect() after the response has been committed
- Caused by: java.lang.IllegalStateException: Ambiguou There is already ‘XXXXXXController‘ bean method
- AppCompat does not support the current theme features
- Error in idea compilation: java.lang.OutOfMemoryError Java heap space and java.lang.StackOverflowError
- Android studio — java.lang.nullpointerexception(no error message)
- An error is reported for the new Android project. Rejecting re init on previously failed
- java.lang.NoSuchMethodError: org.json.JSONObject.put(Java/lang/String; Java/util/Collection;) “209151;”
- Error: Error parsing D:\new_android\Android SDK\system-images\android-25\android-wear\armeabi-v7a\de