builder.setPositiveButton("登陆", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Log.d("0", "0");
EditText et1 = (EditText)findViewById(R.id.et1);
EditText et2 = (EditText)findViewById(R.id.et2);
Log.d("1.1", "1.1");
String str1 = et1.getEditableText().toString();
Log.d("1", "1");
String str2 = et2.getText().toString();
Log.d("2", "2");
File f1 = new File("d:/Android/",str1);
Log.d("3", "3");
.....}error:java.lang.NullPointerException只能查得到前面的2个log,请问问题在哪
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Log.d("0", "0");
EditText et1 = (EditText)findViewById(R.id.et1);
EditText et2 = (EditText)findViewById(R.id.et2);
Log.d("1.1", "1.1");
String str1 = et1.getEditableText().toString();
Log.d("1", "1");
String str2 = et2.getText().toString();
Log.d("2", "2");
File f1 = new File("d:/Android/",str1);
Log.d("3", "3");
.....}error:java.lang.NullPointerException只能查得到前面的2个log,请问问题在哪
请把代码
EditText et1 = (EditText)findViewById(R.id.et1);
EditText et2 = (EditText)findViewById(R.id.et2);改成EditText et1 = (EditText)SampleActivity.this.findViewById(R.id.et1);
EditText et2 = (EditText)SampleActivity.this.findViewById(R.id.et2);
builder.setPositiveButton("登陆", new DialogInterface.OnClickListener() {@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Log.d("0", "0");
EditText et1 = (EditText)findViewById(R.id.et1);
EditText et2 = (EditText)findViewById(R.id.et2);Log.d("1.1", "1.1");
String str1 = et1.getEditableText().toString();
Log.d("1", "1");
if(et2 == null) {
Log.d("log", "et2 null");
}
if(et2.getText() == null {
Log.d("log", "et2 text null");
}
你看下到底是et2为null还是getText()返回的对象为null
LinearLayout test = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.test, null);EditText et1 = (EditText)test.findViewById(R.id.et1);
EditText et2 = (EditText)test.findViewById(R.id.et2);
找个null错,也这么费劲?