我正在爲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