android 单例模式 java.lang.exceptionINinitializererror
PHP中文网
PHP中文网 2017-04-17 11:16:53
0
1
1092
   今天修改android代码的时候出现了一个java.lang.exceptionINinitializererror,在程序刚刚加载的时候会去调用单例模式(FDocument类):

FDocument.Instance().getKindList().clear(); FDocument.Instance().getGradeList().clear(); FDocument.Instance().getCustomerList().clear();来对数据进行初始化操作, 原本是好好的,但是由于我在FDocument类中我需要使用SharedPreferences,所以我让该类继承activity,但是一继承run一下,这下可好报出了

09-11 09:23:50.569: E/AndroidRuntime(22916): java.lang.ExceptionInInitializerError 09-11 09:23:50.569: E/AndroidRuntime(22916): at com.depart.followme.FrmWelCome$1.run(FrmWelCome.java:101) 09-11 09:23:50.569: E/AndroidRuntime(22916): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 的错误,这是为什么,我只是继承了一下activity啊?有大神可以指点小弟我么?

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
小葫芦

If your class is not an activity, you should not inherit the activity. The logic is very strange. Just because you use a sharedpreference, you should inherit the activity? ? ?
Yes, if an ordinary class wants to use context, just pass it in the constructor.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template