求高手 大神 帮下菜
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);
}
}
});
解决方案 »
- Google Maps Android API v2 使用过的吗?
- android 通过wifi和互联网连接打印机实现打印功能怎么做?
- Android 摄像头问题
- 急 android拍照上传空指针
- 求告知,,,急急急!!!
- [Android]应用图标只当做一个开关 ??
- 请教:eclipse的android的SDK如何从4.3升级到4.4
- ======== 小白问题,多指教 ============
- android上面支持原生的c语言开发吗?
- RecyclerView适配器onBindViewHolder方法执行
- 4.0的Launcher中CellLayout的缩放是在哪个处理的?
- 求助:关于画三角行的问题
<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