【问题标题】:AlertDialog Incompatible types errorAlertDialog 不兼容类型错误
【发布时间】:2015-08-01 06:47:47
【问题描述】:

我一直在尝试编译这个简单的警报对话框,以便在用户单击提交按钮时显示。编译代码时弹出错误信息:

错误:(33, 74) 错误:不兼容的类型: 无法转换为 Context

这个类叫Login_Activity,继承BaseActivity,继承Activity。

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    mUserNameEt = (EditText) findViewById(R.id.login_username_et);
    mPasswordEt = (EditText) findViewById(R.id.login_password_et);
    mSubmitBtn = (Button) findViewById(R.id.login_submit_btn);

    mSubmitBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            AlertDialog.Builder messageBox = new AlertDialog.Builder(this);
            messageBox.setTitle("Atlas Box");
            messageBox.setMessage("Dictionary.");
        }
    });
}

【问题讨论】:

    标签: java android android-sdk-tools


    【解决方案1】:

    改变

    AlertDialog.Builder messageBox = new AlertDialog.Builder(this);
    

    AlertDialog.Builder messageBox = new AlertDialog.Builder(youractivityname.this);
    

    【讨论】:

      猜你喜欢
      • 2013-09-23
      • 2011-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-11
      • 2013-10-29
      • 2013-10-14
      相关资源
      最近更新 更多