尝试查找ViewById时抛出NullpointerException

尝试查找ViewById时抛出NullpointerException,第1张

尝试查找ViewById时抛出NullpointerException

从片段编写代码以初始化按钮,因为您的按钮进入片段布局而不是活动布局。

@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,        Bundle savedInstanceState) {    View rootView = inflater.inflate(R.layout.fragment_main, container, false);    Button login = (Button) rootView.findViewById(R.id.loginButton);    login.setonClickListener(new View.onClickListener() {        @Override        public void onClick(View arg0) { Intent intent = new Intent(MainActivity.this,         LoginActivity.class); startActivity(intent);        }    });    return rootView;}

而从删除登录按钮相关的代码

onCreate
Activity



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

原文地址:https://54852.com/zaji/5586620.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-14

发表评论

登录后才能评论

评论列表(0条)

    保存