我正在尝试在我的Android应用程序中包含Amazon广告横幅。我正在关注
快速入门指南(https://developer.amazon.com/docs/mobile-ads/mb-quick-start.html)。
设置应用密钥后,我初始化adView变量:
this.adView = (AdLayout) findViewById(R.id.adview);
但变量adView变为红色并显示警告:无法解析符号
因此,猜测此adView变量的类型为:com.amazon.device.ads.AdLayout,
我改为实施:
com.amazon.device.ads.AdLayout adView = (AdLayout) findViewById(R.id.adview);
AdTargetingOptions adOptions = new AdTargetingOptions();
但是,如果我运行代码,则会得到:NullPointerException,其中:
this.adView.loadAd(adOptions);
似乎它们已正确实例化,所以我在这里想念什么?
顺便说一句,他们建议包括Google Play服务SDK,但特定的Google网站实际上并未指定我们应添加的库。而且添加所有Play库似乎很不方便。我想他们暗中建议安装Play库来运行Google移动广告(com.google.android.gms:play-services-ads:15.0.1),对吧?
您能指出一个实际运行亚马逊横幅的基本Android应用程序,这样我可以估算出我自己的应用程序无法正常运行吗?谢谢
异常堆栈(如果相关):
E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb40fe6a0
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.languagematerial.lmmovies, PID: 5975
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean com.amazon.device.ads.AdLayout.loadAd(com.amazon.device.ads.AdTargetingOptions)' on a null object reference
at com.languagematerial.lmmovies.LMMoviesMainActivity.routine_ConfigsetLanguageSettings_Dialog(LMMoviesMainActivity.java:4376)
at com.languagematerial.lmmovies.LMMoviesMainActivity$118.onClick(LMMoviesMainActivity.java:4064)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I/Process: Sending signal. PID: 5975 SIG: 9
应用程序终止。