[英]Android/Java - Can't set ad size
I am trying to use AdMob in Android and am following tutorials. 我正在尝试在Android中使用AdMob,并且正在学习教程。 I have successfully downloaded, installed and added the Google Play Services library.
我已经成功下载,安装并添加了Google Play服务库。 Nearly everything seems fine.
几乎一切似乎都很好。
However Eclipse stubbornly gives a red underline under the "adView.setAdSize" bit. 但是,Eclipse固执地在“ adView.setAdSize”位下给出了一个红色下划线。 The error message says "The method setAdSize(AdSize) in the type AdView is not applicable for the arguments (AdSize)".
错误消息显示“类型为AdView的setAdSize(AdSize)方法不适用于参数(AdSize)”。 I don't see what's wrong, that code is in line with all tutorials and documentation I can find, and why would setAdSize(AdSize) not take in AdSize as an argument?
我看不出有什么问题,该代码与我可以找到的所有教程和文档一致,为什么setAdSize(AdSize)不能将AdSize作为参数? That doesn't make sense to me.
这对我来说没有意义。
Unfortunately setting the ad size is necessary for the code to run so I can't just remove that bit. 不幸的是,设置代码的大小是运行代码所必需的,因此我不能仅仅删除这一部分。 Relevant code is below.
相关代码如下。 Thanks to anyone that can help.
感谢任何可以提供帮助的人。
...
import com.google.ads.AdSize;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class MainActivity extends ActionBarActivity{
private AdView adView;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
// Create the adView.
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId("ID REMOVED FOR PRIVACY REASONS");
...
}
...
}
Change: 更改:
import com.google.ads.AdSize;
For: 对于:
import com.google.android.gms.ads.AdSize;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.