我在android中生成了一个click事件,我用这种方式写了代码
public class LoginActivity extends AppCompatActivity {
Button btnLogin;
EditText inputEmail,inputPassword;
protected String enteredEmail;
String enteredPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
// inputEmail = (EditText) findViewById(R.id.email);
// inputPassword = (EditText) findViewById(R.id.password);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(i);
}});}
但得到以下错误
TextInputLayout: EditText added is not a TextInputEditText. Please
> switch to using that class instead. 03-11 01:41:52.214
> 21936-21936/com.example.smartlayer.myhive_app I/TextInputLayout:
> EditText added is not a TextInputEditText. Please switch to using that
> class instead. 03-11 01:41:52.294
> 21936-21936/com.example.smartlayer.myhive_app D/AndroidRuntime:
> Shutting down VM 03-11 01:41:52.294
> 21936-21936/com.example.smartlayer.myhive_app W/dalvikvm: threadid=1:
> thread exiting with uncaught exception (group=0xb4ae3ba8) 03-11
> 01:41:52.334 21936-21936/com.example.smartlayer.myhive_app
> E/AndroidRuntime: FATAL EXCEPTION: main
> Process: com.example.smartlayer.myhive_app, PID: 21936
> java.lang.RuntimeException: Unable to start activity
我如何解决这个错误?
答案 0 :(得分:0)
您缺少初始化Button
btnLogin = (Button) findViewById(R.id.Set_Button_Id);
<强>像强>
btnLogin = (Button) findViewById(R.id.Set_Button_Id);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(i);
}});}