I want to release AlertDialog, but I get a build error.

Asked 2 years ago, Updated 2 years ago, 95 views

Problems you are having

I want to issue an AlertDialog, but I get a build error.
I looked it up, but I don't know, so please let me know.

valdialogBuilder=AlertDialog.Builder(this)

Here's an error message.

Error Messages

Error: (195 and 45) None of the following functions can be called with the arguments supplied:
public constructor Builder (context:android.content.Context!) defined in android.app.AlertDialog.Builder
public constructor Builder(context:android.content.Context!,theme:kotlin.Int)defined in android.app.AlertDialog.Builder
package jp.yahuu.hogehoge.app.activities

import android.app.AlertDialog
import android.content.DialogInterface
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.SearchRecentSuggestions
import android.webkit.JavascriptInterface
import android.widget.Toast
import jp.yahuu.hogehoge.app.R
import jp.yahuu.hogehoge.app.UserLogoutActivity
import jp.yahuu.hogehoge.app.advertising.AdvertisingIdentifierManager
import jp.yahuu.hogehoge.app.constants.Constants
import jp.yahuu.hogehoge.app.data.feed.user.User
import jp.yahuu.hogehoge.app.fragment.WebFragment
import jp.yahuu.hogehoge.app.proguardHelper.NonObfuscate
import jp.yahuu.hogehoge.app.suggestionsProvider.SuggestionsProvider
import jp.yahuu.hogehoge.app.web.*
import kotlin.properties.Delegates

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        // If you choose to erase the history erasure
        private fun showLogoutDialog(){

            // AlertDialog.Builder Object Generation

            valdialogBuilder = AlertDialog.Builder(this)

            dialogBuilder.setTitle("Delete Search History")
            DialogBuilder.setMessage(" operation cannot be undone.Would that be all right?")

            valself = this

            dialogBuilder.setPositiveButton("Delete", object:DialogInterface.OnClickListener{

                override fun onClick (dialog:DialogInterface, which:Int) {

//                    val Suggestions = SearchRecentSuggestions(
//                            self,
//                            SuggestionsProvider.Authority,
//                            SuggestionsProvider.Mode
//                    )
//
//                    Suggestions.clearHistory()
//
//                    Toast.makeText(self, "Search History Deleted", Toast.LENGTH_SHORT).show()

                }

            })

            dialogBuilder.setNegotisticalButton("Cancel", object:DialogInterface.OnClickListener{

                override fun onClick (dialog:DialogInterface, which:Int) {

                    dialog.cancel()

                }

            })

            dialogBuilder.setCancelable(true)
            dialogBuilder.create().show()

        }

java android kotlin

2022-09-30 20:59

1 Answers

Instead of this, try naming activity in the following format:

before change:

AlertDialog.Builder(this)

after modification:

AlertDialog.Builder (yourActivityName.this)

This post was posted as a community wiki based on @user9156's comments.


2022-09-30 20:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.