简体   繁体   English

错误:构造函数Object(EditText)未定义

[英]Error: The constructor Object(EditText) is undefined

I'm getting an error in this method: "The constructor Object(EditText) is undefined" 我在此方法中收到错误:“构造函数Object(EditText)未定义”

private void setupAlert()
    {
        Log.d(TAG, "setupAlert()");
        LayoutInflater li = LayoutInflater.from(this);
        View promptsView = li.inflate(R.layout.emaildialog, null);
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
        alertDialogBuilder.setView(promptsView);
        final EditText userInput = (EditText)promptsView.findViewById(R.id.editTxtEmailAddress);
        alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int id)
            {
                updatePref(userInput.getText().toString());
                Log.d(MainActivity.TAG, "setupAlert: getPreference()=" + getPreference());
                takeSnapNow();
            }
        });
        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }

protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.colour_selector);
        Log.d(TAG, "onCreate: getPreference()=" + getPreference());
        if (getPreference().equals("")) {
            setupAlert();
            takeSnapNow();
        } else {
            takeSnapNow();
        }
    }

private void takeSnapNow()
    {
        String fileName = "TempImage.jpg";
        ContentValues values = new ContentValues();
        values.put(MediaStore.Images.Media.TITLE, fileName);
        values.put(MediaStore.Images.Media.DESCRIPTION, "Captured by XYZ app");
        imageUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
    }

Please suggest the solution to this error. 请提出针对该错误的解决方案。

Edit: Corrected the above error by removing UserInput as suggested by others. 编辑:通过删除其他人建议的UserInput纠正了上述错误。 However the alertDialog is still not shown. 但是,alertDialog仍然没有显示。 The logic is to check the sharedpref initially in onCreate, and if not found, call setupAlert() method to get email ID from user. 逻辑是先在onCreate中检查sharedpref,如果找不到,请调用setupAlert()方法从用户获取电子邮件ID。 Any clues? 有什么线索吗? Changed code updated in the above snippet. 更改了以上代码段中更新的代码。

DialogInterface.OnClickListener doesn't take an EditText as a constructor parameter and you don't need to do that ! DialogInterface.OnClickListener不需要将EditText作为构造函数参数,因此您无需这样做! you can use userInput without passing it to DialogInterface.OnClickListener , just use it as follow 您可以使用userInput而不将其传递给DialogInterface.OnClickListener ,只需按以下方式使用

alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {

Why are you using " new DialogInterface.OnClickListener(userInput) "? 为什么使用“ new DialogInterface.OnClickListener(userInput) ”?

Just use new DialogInterface.OnClickListener() 只需使用新的DialogInterface.OnClickListener()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM