做个软件的登入注册界面,可是刚开始的一个登录就出现问题了,代码如下
public class Login extends Activity {
Button login, register, out;
private static EditText username, password;
Intent intent = null;
private ButtonListener listener = new ButtonListener(); @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.down); login = (Button) findViewById(R.id.btn_Login);
register = (Button) findViewById(R.id.btn_Reset);
out = (Button) findViewById(R.id.btn_Out); username = (EditText) findViewById(R.id.et_staff_no);
password = (EditText) findViewById(R.id.et_password); login.setOnClickListener(listener);
register.setOnClickListener(listener);
out.setOnClickListener(listener); } private final class ButtonListener implements OnClickListener { @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_Login:
Toast.makeText(Login.this, "登录了", 1).show();
intent = new Intent(Login.this, Down.class);
startActivity(intent);
break;
case R.id.btn_Reset:
Toast.makeText(Login.this, "注册了", 1).show();
break;
case R.id.btn_Out:
Toast.makeText(Login.this, "退出了", 1).show();
break;
}
} }我看了半天不知道哪里有问题,LOGCAT报错是login = (Button) findViewById(R.id.btn_Login);
register = (Button) findViewById(R.id.btn_Reset);
out = (Button) findViewById(R.id.btn_Out);
为空,可是我之前也写过这样的方法的,可以编译,但是现在怎么就不行了,实在找不出问题了,特来求教android 空指针异常
public class Login extends Activity {
Button login, register, out;
private static EditText username, password;
Intent intent = null;
private ButtonListener listener = new ButtonListener(); @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.down); login = (Button) findViewById(R.id.btn_Login);
register = (Button) findViewById(R.id.btn_Reset);
out = (Button) findViewById(R.id.btn_Out); username = (EditText) findViewById(R.id.et_staff_no);
password = (EditText) findViewById(R.id.et_password); login.setOnClickListener(listener);
register.setOnClickListener(listener);
out.setOnClickListener(listener); } private final class ButtonListener implements OnClickListener { @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_Login:
Toast.makeText(Login.this, "登录了", 1).show();
intent = new Intent(Login.this, Down.class);
startActivity(intent);
break;
case R.id.btn_Reset:
Toast.makeText(Login.this, "注册了", 1).show();
break;
case R.id.btn_Out:
Toast.makeText(Login.this, "退出了", 1).show();
break;
}
} }我看了半天不知道哪里有问题,LOGCAT报错是login = (Button) findViewById(R.id.btn_Login);
register = (Button) findViewById(R.id.btn_Reset);
out = (Button) findViewById(R.id.btn_Out);
为空,可是我之前也写过这样的方法的,可以编译,但是现在怎么就不行了,实在找不出问题了,特来求教android 空指针异常
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货