[英]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.