简体   繁体   中英

How can I solve incompatible types error for my app in android studio?

I tried running a popup screen for an app I'm creating on android studio and I received a "incompatible types: cannot be converted to Context" error on the build. android studio

Try this :-

builder = AlertDialog.Builder(MainActivity.this);

To refer to the instance of MainActivity, you have to use MainActivity.this. The this keywork inside onClickListener() refers to the instance of the anonymous class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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