setclicklistener出现java.lang.nullpointerexception错误怎么解决啊

Miss--W 2017-08-14 11:07:00

Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
mEmailSignInButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Intent intent =new Intent(LoginActivity.this,Main2Activity.class);
startActivity(intent);
}
});
在setOnclickListener处出现警告,警告内容是Method invocation 'setOnClickListener' may produce 'java.lang.nullpointerexception'
这怎么解决呢,谢谢
...全文
577 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
smile_邝野 2017-08-14
  • 打赏
  • 举报
回复
引用 2 楼 weixin_39775095 的回复:
嗯是的,注册了 现在的问题是 if (cancel) { // There was an error; don't attempt login and focus the first // form field with an error. focusView.requestFocus(); } else { // Show a progress spinner, and kick off a background task to // perform the user login attempt. showProgress(true); mAuthTask = new UserLoginTask(email, password); mAuthTask.execute((Void) null); }
你这个cancel应该是取消的按钮吧
Miss--W 2017-08-14
  • 打赏
  • 举报
回复
嗯是的,注册了 现在的问题是 if (cancel) { // There was an error; don't attempt login and focus the first // form field with an error. focusView.requestFocus(); } else { // Show a progress spinner, and kick off a background task to // perform the user login attempt. showProgress(true); mAuthTask = new UserLoginTask(email, password); mAuthTask.execute((Void) null); }
smile_邝野 2017-08-14
  • 打赏
  • 举报
回复
你的activity都在清单文件注册了吗?
Miss--W 2017-08-14
  • 打赏
  • 举报
回复
引用 5 楼 chengzhouyang11 的回复:
贴下完整日志,还有requestFocus()方法体
什么意思?
chengzhouyang11 2017-08-14
  • 打赏
  • 举报
回复
贴下完整日志,还有requestFocus()方法体
Miss--W 2017-08-14
  • 打赏
  • 举报
回复
这是创建了Activity后自己出来的一段程序,我也不是太懂 上面是这样的 boolean cancel ; View focusView ; if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) { mPasswordView.setError(getString(R.string.error_invalid_password)); focusView = mPasswordView; cancel = true; // Check for a valid email address. if (TextUtils.isEmpty(email)) { mEmailView.setError(getString(R.string.error_field_required)); focusView = mEmailView; cancel = true; } else if (!isEmailValid(email)) { mEmailView.setError(getString(R.string.error_invalid_email)); focusView = mEmailView; cancel = true; } if (cancel) { // There was an error; don't attempt login and focus the first // form field with an error. focusView.requestFocus(); } else { // Show a progress spinner, and kick off a background task to // perform the user login attempt. showProgress(true); mAuthTask = new UserLoginTask(email, password); mAuthTask.execute((Void) null); }

80,337

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧