求高手 大神 帮下菜
private EditText text1, text2;
private Button btn1, btn2;
private String njid; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text1=(EditText)findViewById(R.id.user_name);
text2=(EditText)findViewById(R.id.passwordEdit);
btn1 = (Button) findViewById(R.id.loginBtn);
btn2 = (Button) findViewById(R.id.loginReqister); btn1.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
String name = text1.getText().toString(); // 就这里啊 报错 nullpointerexception!!!!!!!!!!!!!!!
Log.i("Message",name );
String pwd = text2.getText().toString();
if (name != null && pwd != null) {
Intent intent = new Intent(LoginTest.this,
LoginSecond.class);
Bundle bundle = new Bundle();
bundle.putString("name", name);
bundle.putString("pwd", pwd); intent.putExtras(bundle);
startActivity(intent);
}
}
});
private EditText text1, text2;
private Button btn1, btn2;
private String njid; @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text1=(EditText)findViewById(R.id.user_name);
text2=(EditText)findViewById(R.id.passwordEdit);
btn1 = (Button) findViewById(R.id.loginBtn);
btn2 = (Button) findViewById(R.id.loginReqister); btn1.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub
String name = text1.getText().toString(); // 就这里啊 报错 nullpointerexception!!!!!!!!!!!!!!!
Log.i("Message",name );
String pwd = text2.getText().toString();
if (name != null && pwd != null) {
Intent intent = new Intent(LoginTest.this,
LoginSecond.class);
Bundle bundle = new Bundle();
bundle.putString("name", name);
bundle.putString("pwd", pwd); intent.putExtras(bundle);
startActivity(intent);
}
}
});
<EditText android:textSize="16.0sp" android:textColor="#ffa63104" android:textColorHint="#fff3b59c" android:id="@+id/userName" android:paddingLeft="10.0px" android:focusable="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="195.0px" android:singleLine="true" style="@style/my_edittext_style" />
<EditText android:textSize="16.0sp" android:textColor="#ffa63104" android:textColorHint="#fff3b59c" android:id="@+id/passwordEdit" android:paddingLeft="10.0px" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="15.0px" android:password="true" android:singleLine="true" style="@style/my_edittext_style" />
<Button android:textSize="17.0sp" android:textColor="#ffffffff" android:id="@+id/loginBtn" android:background="@drawable/login_amendbtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="30.0px" android:text="登录" />
<Button android:textSize="17.0sp" android:textColor="#ffffffff" android:id="@+id/loginReqister" android:background="@drawable/login_amendbtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="15.0px" android:text="注册新会员" />
</LinearLayout>
XML的文件
改成
text1=(EditText)findViewById(R.id.userName);
而你代码中是user_name