android–Screen旋转后的nullPointerException

android–Screen旋转后的nullPointerException,第1张

概述我在屏幕旋转后得到对象LinearLayout返回的nullPointerException异常,虽然我在onCreate()super.onCreate(null)中传递null;.我知道Activity必须被销毁并重新创建旁边我传递的savedInstanceState=null表示Activity应该在旋转后开始,因为它是第一次启动,为什么我在旋转后得到这个

我在屏幕旋转后得到对象linearLayout返回的nullPointerException异常,虽然我在onCreate()super.onCreate(null)中传递null; .
我知道Activity必须被销毁并重新创建旁边我传递的savedInstanceState = null表示Activity应该在旋转后开始,因为它是第一次启动,为什么我在旋转后得到这个Exception?

onCreate()片段,其中linearLayout对象称为historyText

linearLayout historyText ;  // this return exception if it used after rotation .     @OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(null);    setContentVIEw(R.layout.activity_main);    historyText = (linearLayout) findVIEwByID(R.ID.historyLayoutText);     Log.e("HISTORYVISIBIliTY", "VISIBIliTY = "+historyText.getVisibility());    getwindow().getDecorVIEw().setsystemUIVisibility(            VIEw.SYstem_UI_FLAG_LAYOUT_Stable                    | VIEw.SYstem_UI_FLAG_LAYOUT_FulLSCREEN);    database = new Database(this);    Bundle extras = getIntent().getExtras();    intent = extras.getInt("activity");    p = new Progress();    getSupportFragmentManager().beginTransaction()                .add(R.ID.group, p)                .commit();    orIEntation = getRotation();    switch (orIEntation){        case "p" :            addplus();    }}

logcat的

    10-07 22:21:24.365: E/AndroIDRuntime(7768): FATAL EXCEPTION: main10-07 22:21:24.365: E/AndroIDRuntime(7768): Process: developer.mohab.gymee, PID: 776810-07 22:21:24.365: E/AndroIDRuntime(7768): java.lang.RuntimeException: Unable to start activity ComponentInfo{developer.mohab.gymee/developer.mohab.gymee.Cardio.Cardio}: java.lang.NullPointerException: Attempt to invoke virtual method 'int androID.Widget.linearLayout.getVisibility()' on a null object reference10-07 22:21:24.365: E/AndroIDRuntime(7768):     at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2379)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2442)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at androID.app.ActivityThread.handle@R_253_4404@Activity(ActivityThread.java:4053)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at androID.app.ActivityThread.access0(ActivityThread.java:156)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1357)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at androID.os.Handler.dispatchMessage(Handler.java:102)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at androID.os.Looper.loop(Looper.java:211)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at androID.app.ActivityThread.main(ActivityThread.java:5389)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at java.lang.reflect.Method.invoke(Native Method)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at java.lang.reflect.Method.invoke(Method.java:372)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:815)10-07 22:21:24.365: E/AndroIDRuntime(7768): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int androID.Widget.linearLayout.getVisibility()' on a null object reference10-07 22:21:24.365: E/AndroIDRuntime(7768):     at developer.mohab.gymee.Cardio.Cardio.onCreate(Cardio.java:76)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at androID.app.Activity.performCreate(Activity.java:5990)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)10-07 22:21:24.365: E/AndroIDRuntime(7768):     at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2332)10-07 22:21:24.365: E/AndroIDRuntime(7768):     ... 11 more10-07 22:21:24.633: E/SurfaceFlinger(319): rejecting buffer: bufWIDth=1358, bufheight=624, front.active.{w=193, h=193}

解决方法:

旋转设备时,活动及其上的所有碎片都将被销毁.要避免这种情况,您应该修改AndroIDManifest.xml

<activity            androID:name=".MainActivity"            androID:configChanges="orIEntation|screenSize"

这样可以防止异常

总结

以上是内存溢出为你收集整理的android – Screen旋转后的nullPointerException全部内容,希望文章能够帮你解决android – Screen旋转后的nullPointerException所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1115720.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存