我正在为android中的应用程序构建登录页面。但在测试时会在AlertDialog.Builder中给出错误,并说它没有被定义。我用它在另一个应用程序,并完美地工作。提前致谢。 这是代码:Android程序中的AlertDialog.Builder显示错误
package project.login;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class LoginActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Button launch = (Button)findViewById(R.id.login_button);
launch.setOnClickListener(new OnClickListener()
{
public void onClick(View view)
{ EditText usernameEditText = (EditText) findViewById(R.id.username);
EditText passwordEditText = (EditText) findViewById(R.id.password);
String sUsername = usernameEditText.getText().toString();
String sPassword = passwordEditText.getText().toString();
if(usernameEditText == null || passwordEditText == null) {
new AlertDialog.Builder(this)
.setTitle("Error")
.setMessage("You can't let the fields empty")
.show();
}
}
}
);
}
}
你能发布你正在得到的确切的错误信息吗? –
“”构造函数AlertDialog.Builder(new View.OnClickListener(){})未定义“” – kiran