简体   繁体   English

不兼容的类型:<anonymous onclicklistener> 无法转换为 Context</anonymous>

[英]incompatible types: <anonymous OnClickListener> cannot be converted to Context

when i run app it gives the following error当我运行应用程序时出现以下错误

incompatible types: <anonymous OnClickListener> cannot be converted to Context
                InterstitialAd.load(this,ForexScalping.this.getString(R.string.main_inter), adRequest,

im still new to code so i have no clue.我对代码还是陌生的,所以我不知道。 here is the java file这是 java 文件





public class ForexScalping extends AppCompatActivity {

    Button button2;

    private InterstitialAd mInterstitialAd;

    public void onBackPressed()
    {
        super.onBackPressed();
        if (mInterstitialAd != null)
        {
            mInterstitialAd.show(ForexScalping.this);
            return;
        }
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_forex_scalping);

        this.button2 = findViewById(R.id.button2);
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                final ProgressDialog pd = new ProgressDialog(ForexScalping.this);
                pd.setCancelable(false);
                pd.setMessage("Loading...");
                pd.show();
                AdRequest adRequest = new AdRequest.Builder().build();

                InterstitialAd.load(this,ForexScalping.this.getString(R.string.main_inter), adRequest,
                        new InterstitialAdLoadCallback() {
                            @Override
                            public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
                                // The mInterstitialAd reference will be null until
                                // an ad is loaded.
                                mInterstitialAd = interstitialAd;
                                mInterstitialAd.show(ForexScalping.this);
                            }

  

I have tried adding the View.OnClicklistener to the public but still it brings the same error.我已经尝试将 View.OnClicklistener 添加到公众中,但它仍然会带来同样的错误。 and yes I have tried all the answers given on errors related to this.是的,我已经尝试了所有与此相关的错误答案。

remove this from InterstitialAd.load( this ,ForexScalping.this.getString with ForexScalping.this从 InterstitialAd.load( this , ForexScalping.this.getString with ForexScalping.this

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

相关问题 不兼容的类型: <anonymous TextWatcher> 无法转换为上下文 - incompatible types: <anonymous TextWatcher> cannot be converted to Context 不兼容的类型:Mainactivity无法转换为OnClickListener - Incompatible types: Mainactivity cannot be converted to OnClickListener 不兼容的类型:无法转换为 Context - incompatible types: cannot be converted to Context 错误:不兼容的类型:SnekEngine 无法转换为 Context - error: incompatible types: SnekEngine cannot be converted to Context 错误:不兼容的类型:上下文无法转换为 HomeMenu - error: incompatible types: Context cannot be converted to HomeMenu 错误:类型不兼容:HomeFragment无法转换为上下文 - error: incompatible types: HomeFragment cannot be converted to Context 不兼容的类型:Widget 无法转换为 Context - Incompatible types: Widget cannot be converted to Context 错误:类型不兼容:NewSubscription无法转换为上下文 - error: incompatible types: NewSubscription cannot be converted to Context 错误:不兼容的类型:ImageActivity 无法转换为 Context - error: incompatible types: ImageActivity cannot be converted to Context 不兼容的类型:FirebaseMessagingService 无法转换为 Context - Incompatible types: FirebaseMessagingService cannot be converted to Context
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM