Android studio报: java.lang.ExceptionInInitializerError 错误

网友投稿 317 2023-06-05


Android studio报: java.lang.ExceptionInInitializerError 错误

一、问题描述

android studio导入一个项目报一堆错误:

Process: xhs.com.xhswelcomeanim, PID: 1416

java.lang.ExceptionInInitializerError

at com.werb.gankwithzhihu.ui.fragment.ZhihuFragment.createPresenter(ZhihuFragment.java:33)

at com.werb.gankwithzhihu.ui.fragment.ZhihuFragment.createPresenter(ZhihuFragment.java:25)

at com.werb.gankwithzhihu.ui.base.MVPBaseFragment.onCreate(MVPBaseFragment.java:35)

at android.support.v4.app.Fragment.performCreate(Fragment.java:2068)

at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1055)

at android.support.v4.app.BackStackRecord.setLastIn(BackStackRecord.java:838)

at android.support.v4.app.BackStackRecord.calculateFragments(BackStackRecord.java:861)

at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:719)

at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:1638)

at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:679)

at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:143)

at android.support.v4.view.ViewPager.populate(ViewPager.java:1240)

at android.support.v4.view.ViewPager.populate(ViewPager.java:1088)

at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1614)

at android.view.View.measure(View.java:18026)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5702)

at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692)

at android.widget.LinearLayout.measureVertical(LinearLayout.java:760)

at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)

at android.view.View.measure(View.java:18026)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5702)

at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:700)

at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:90)

at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1364)

at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:765)

at android.view.View.measure(View.java:18026)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5702)

at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692)

at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1244)

at android.widget.LinearLayout.onMeasure(LinearLayout.java:631)

at android.view.View.measure(View.java:18026)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5702)

at android.widget.FrameLayout.onMeasure(FrameLayout.java:465)

at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)

at android.view.View.measure(View.java:18026)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5702)

at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692)

at android.widget.LinearLayout.measureVertical(LinearLayout.java:760)

at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)

at android.view.View.measure(View.java:18026)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5702)

at android.widget.FrameLayout.onMeasure(FrameLayout.java:465)

at android.view.View.measure(View.java:18026)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5702)

at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1692)

at android.widget.LinearLayout.measureVertical(LinearLayout.java:760)

at android.widget.LinearLayout.onMeasure(LinearLayout.java:629)

at android.view.View.measure(View.java:18026)

at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5702)

at android.widget.FrameLayout.onMeasure(FrameLayout.java:465)

at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2785)

at android.view.View.measure(View.java:18026)

at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2456)

at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1440)

at android.view.View

报 java.lang.ExceptionInInitializerError错误,网上的解析是:

当在静态初始化块中出现了异常的时候,JVM会抛出 java.lang.ExceptionInInitializerError异常。如果你了解Java中的静态变量,你会知道它们是在类加载的时候进行初始化的。如果在这个静态变量初始化的过程中出现了异常,那么就会抛出 java.lang.ExceptionInInitializerError异常。任何异常都可能会引发这种情况,比如说,java.lang.ArrayIndexOutOfBound或者java.lang.NullPointerException。Java开发人员通常会被这个错误弄晕,他觉得自己并没有定义任何的静态初始化块,为什么还会抛出ExceptionInInitializerError异常;事实上,Java默认会将静态变量的初始化放在一个默认的静态初始化块中,然后按它们在源文件中声明的顺序来进行初始化。

二、解决方法

找了半天没发现有什么错误啊,最后在AndroidManifest.xml清单文件中,发现了问题所在:

他在这引用了MaApp这个类:

而MaApp继承的是全局的application这个类,所以在初始化时如果没有引用进来的话,就会报错,而我的那个清单文件中并没有引用进来所以报错了.把他加进来就好了:


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:gson ajax 数字精度丢失问题的解决方法
下一篇:JAVA String转化成java.sql.date和java.sql.time方法示例
相关文章

 发表评论

暂时没有评论,来抢沙发吧~