由网友(星空迷上山野)分享简介:如何编辑按钮从另一个活动?它返回我的java.lang.IllegalStateException:无法执行活动的方法显示java.lang.NullPointerException:产生的原因当我想getButton.setEnabled(假);其中按钮getButton =(按钮)findViewById(R.i...![行动召唤按钮在网页中的实例与实践](/d/file/2023/09-17/04a770c76a2994c212fd457996a73d56.png)
如何编辑按钮从另一个活动?
它返回我的
java.lang.IllegalStateException:无法执行活动的方法
显示java.lang.NullPointerException:产生的原因
当我想
getButton.setEnabled(假);
其中
按钮getButton =(按钮)findViewById(R.id.buttonGet);
![行动召唤按钮在网页中的实例与实践](/d/file/2023/09-17/04a770c76a2994c212fd457996a73d56.png)
解决方案
请确保你调用的setContentView之前,你得到的引用您的按钮,即做到这一点:
的setContentView(R.layout.my_activity_layout);
在这样的:
按钮getButton =(按钮)findViewById(R.id.buttonGet);
How can I edit a button from another Activity?
It returns me an
java.lang.IllegalStateException: Could not execute method of the activity
Caused by: java.lang.NullPointerException
When I want to
getButton.setEnabled(false);
where
Button getButton = (Button)findViewById(R.id.buttonGet);
解决方案
Make sure you have called setContentView before you get a reference to your button, i.e do this:
setContentView(R.layout.my_activity_layout);
before this:
Button getButton = (Button)findViewById(R.id.buttonGet);
相关推荐
最新文章