Android错误之 java.lang.IllegalStateException: System services not available to Activities before onC
来源:互联网 发布:知乎 怎么死最舒服 编辑:程序博客网 时间:2024/05/19 19:15
全错误日志如下:
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)
错误代码如下:
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);
果然写到了onCreate的上面,将其放入onCreate方法运行即可。
0 0
- Android错误之 java.lang.IllegalStateException: System services not available to Activities before onC
- android java.lang.IllegalStateException: System services not available to Activities before onCreate
- android java.lang.IllegalStateException: System services not available to Activities before onCreate
- android java.lang.IllegalStateException: System services not available to Activities before onCreat
- System services not available to Activities before onCreate()错误解决方法
- 报错:System services not available to Activities before onCreate()
- System services not available to Activities before onCreate()
- [2015/05/08] System services not available to Activities before onCreate()
- java.lang.IllegalStateException: JodaTime library not available - @DateTimeFormat not supported
- java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking
- java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before
- java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before
- openfire asmack java.lang.IllegalStateException: Not connected to server.错误解决办法
- Android - 错误: java.lang.IllegalStateException: Already attached
- android studio著名错误 java.lang.IllegalStateException:
- Android Fragment异常:java.lang.IllegalStateException: Fragment XXXFragment not attached to Activity
- Android Fragment异常java.lang.IllegalStateException: Fragment not attached to Activity
- android 6.0+ java.lang.IllegalStateException did not call finish() prior to onResume() completing
- Q40:数组中只出现一次的数字
- Laravel队列的心得笔记
- 查看当前mysql使用频繁的sql语句
- Java 8系列之重新认识HashMap
- leetcode:295. Find Median from Data Stream
- Android错误之 java.lang.IllegalStateException: System services not available to Activities before onC
- 文件上传、压缩解压 操作
- oninput那些事
- 创建 Entity Framework 链接 MySql
- 【杭电oj2031】进制转换
- poj入门水题整理2
- DOM与DOM4J对XML文件的解析
- 8. String to Integer (atoi)
- 滑动均值Moving Average与中值滤波Moving Median