IT修真院·坑乎 | Java(后端),CSS(前端),JavaScript(前端),PM(产品经理),UI(交互设计),QA(测试),Android(安卓APP),iOS(苹果APP),OP(运维),Python(后端)日常在线问答学习平台
咨询电话 : 010-59478634
切换导航
首页
我的提问
我的回答
我的点赞
消息通知
个人主页
×
提示
尚未登陆,前往官网登陆?
×
提示
尚未登陆,前往官网登陆?
CSS
JS
Android
IOS
JAVA
OP
PM
UI
QA
求职辅导
Python
运营
动画师
AIGC
CSS
JS
Android
IOS
JAVA
OP
PM
UI
QA
求职辅导
Python
运营
动画师
AIGC
所有任务
任务1
任务2
任务3
任务4
任务5
任务6
任务7
任务8
任务9
任务10
任务11
任务12
任务13
任务14
任务15
任务16
任务17
全部
问题
已收录
问题
未收录
问题
没有找到答案,去提问>>>
该问题已被官方收录
创建了一个View,对其使用setVisibility()方法,运行时报空指针
1
1
class="cursor-pointer"> 详细描述
创建一个View,初始化时将其隐藏,过程很简单,以前经常这么用,也没这个问题。
class="cursor-pointer"> 截图
2018-11-10 20:41:32.250 25639-25639/? E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.forrestsu.logintest, PID: 25639 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.forrestsu.logintest/com.example.forrestsu.logintest.activity.MapModeActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setVisibility(int)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2822) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:251) at android.app.ActivityThread.main(ActivityThread.java:6572) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setVisibility(int)' on a null object reference at com.example.forrestsu.logintest.activity.MapModeActivity.initView(MapModeActivity.java:96) at com.example.forrestsu.logintest.activity.MapModeActivity.onCreate(MapModeActivity.java:86) at android.app.Activity.performCreate(Activity.java:6975) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2775) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:251) at android.app.ActivityThread.main(ActivityThread.java:6572) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 2018-11-10 20:41:32.251 25639-25639/? D/MtaSDK: [main(2): null:61] - MTA has caught the following uncaught exception: 2018-11-10 20:41:32.251 25639-25639/? E/MtaSDK: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.forrestsu.logintest/com.example.forrestsu.logintest.activity.MapModeActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setVisibility(int)' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2822) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:251) at android.app.ActivityThread.main(ActivityThread.java:6572) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setVisibility(int)' on a null object reference at com.example.forrestsu.logintest.activity.MapModeActivity.initView(MapModeActivity.java:96) at com.example.forrestsu.logintest.activity.MapModeActivity.onCreate(MapModeActivity.java:86) at android.app.Activity.performCreate(Activity.java:6975) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2775) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2897) at android.app.ActivityThread.-wrap11(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1598) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:251) at android.app.ActivityThread.main(ActivityThread.java:6572) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
class="cursor-pointer"> 代码
布局文件
代码 private View glassView; ...... glassView = (View) findViewById(R.id.view_glass); glassView.setVisibility(GONE); glassView.setOnClickListener(new MyOnClickListener());
创建一个View,初始化时将其隐藏,过程很简单,以前经常这么用,也没这个问题。
首页
1
末页
去第
页
确定
Copyright ©2015 北京葡萄藤信息技术有限公司 All Rights Reserved | 京ICP备15035574号-1
58
3
1
10