我有 2 堂课,我把我的方法放在了第一堂课
头等舱
public void countIN (View view) {
counter++;
if (counter == 3){
if (mInterstitialAd.isLoaded()){
mInterstitialAd.show();
}
}
}
我想在我的第一堂课中调用我的方法
二等舱
First myMethod = new First();
........
private void onClickButton(final ExpandableLayout expandableLayout) {
expandableLayout.toggle();
myMethod.countIN();
}
但它不起作用,我收到此错误:StackTrace
Error:(85, 17) error: method countIN in class RecyclerViewActivity cannot be applied to given types;
required: View
found: no arguments
reason: actual and formal argument lists differ in length
您可以在调用方法时将 null 作为参数传递
myMethod.countIN(null);
但这仅用于测试和进一步操作,您必须停止将 View 视图作为方法中的参数:
public void countIN () {
counter++;
if (counter == 3){
if (mInterstitialAd.isLoaded()){
mInterstitialAd.show();
}
}
或使用参数
public void countIN (View view) {
counter++;
if (counter == 3){
if (mInterstitialAd.isLoaded()){
mInterstitialAd.show();
view.(do something)
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句