我正在尝试在 android 中做这样的事情。我的意思是我有密码文本框,如果密码正确,我正在尝试使文本视图可见,但我不断显示异常java.lang.nullpointerexception
这是我的代码
public class MainActivity extends Activity {
EditText Password;
Button login;
TextView txtDash;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Password=(EditText)findViewById(R.id.pass);
login=(Button)findViewById(R.id.login);
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View V) {
try {
if (Password.getText().toString().equals("dsml"))
{
txtDash.setVisibility(View.VISIBLE);
login.setVisibility(View.INVISIBLE);
Password.setVisibility(View.INVISIBLE);
}
else
{
Toast.makeText(getBaseContext(), "invalid password - try again", Toast.LENGTH_SHORT).show();
}
}catch(Exception e){
//Log.e("log_tag", "Error"+e.toString());
Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
请任何人帮助摆脱这个