我想在Android游戏中使用AdGob添加广告横幅,使用LibGDX和谷歌播放服务......
你能帮我解决这个错误吗?无法理解为什么它不起作用......:/
我知道这个错误意味着什么,但我真的不知道它在我的代码中链接了什么... (我是java和android dev的新手,还有法语,所以对我来说很难......>。<)
03-19 17:34:13.523: E/AndroidRuntime(5806): FATAL EXCEPTION: main
03-19 17:34:13.523: E/AndroidRuntime(5806): Process: com.louu.aimproject, PID: 5806
03-19 17:34:13.523: E/AndroidRuntime(5806): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.louu.aimproject/com.louu.aimproject.MainActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
03-19 17:34:13.523: E/AndroidRuntime(5806): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2227)
03-19 17:34:13.523: E/AndroidRuntime(5806): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2277)
03-19 17:34:13.523: E/AndroidRuntime(5806): at android.app.ActivityThread.access$800(ActivityThread.java:145)
03-19 17:34:13.523: E/AndroidRuntime(5806): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
03-19 17:34:13.523: E/AndroidRuntime(5806): at android.os.Handler.dispatchMessage(Handler.java:102)
03-19 17:34:13.523: E/AndroidRuntime(5806): at android.os.Looper.loop(Looper.java:136)
03-19 17:34:13.523: E/AndroidRuntime(5806): at android.app.ActivityThread.main(ActivityThread.java:5088)
03-19 17:34:13.523: E/AndroidRuntime(5806): at java.lang.reflect.Method.invokeNative(Native Method)
03-19 17:34:13.523: E/AndroidRuntime(5806): at java.lang.reflect.Method.invoke(Method.java:515)
03-19 17:34:13.523: E/AndroidRuntime(5806): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
03-19 17:34:13.523: E/AndroidRuntime(5806): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
03-19 17:34:13.523: E/AndroidRuntime(5806): at dalvik.system.NativeStart.main(Native Method)
03-19 17:34:13.523: E/AndroidRuntime(5806): Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
03-19 17:34:13.523: E/AndroidRuntime(5806): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:303)
03-19 17:34:13.523: E/AndroidRuntime(5806): at android.app.Activity.requestWindowFeature(Activity.java:3332)
03-19 17:34:13.523: E/AndroidRuntime(5806): at com.louu.aimproject.MainActivity.onCreate(MainActivity.java:62)
03-19 17:34:13.523: E/AndroidRuntime(5806): at android.app.Activity.performCreate(Activity.java:5434)
03-19 17:34:13.523: E/AndroidRuntime(5806): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
03-19 17:34:13.523: E/AndroidRuntime(5806): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2181)
03-19 17:34:13.523: E/AndroidRuntime(5806): ... 11 more
03-19 17:41:44.643: E/dalvikvm(6652): Could not find class 'com.google.android.gms.ads.AdView', referenced from method com.louu.aimproject.MainActivity.onCreate
代码
@Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
gameHelper.setup(this);
RelativeLayout layout = new RelativeLayout(this);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
View gameView = initializeForView(new TutorialLibgdxGameservices(this), false);
AdView adView = new AdView(this);
adView.setAdUnitId("ca-app-pub-7435783642832057/7018436522");
adView.setAdSize(AdSize.SMART_BANNER);
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
//.addTestDevice("") // Mon téléphone est un nexus 5
.build();
layout.addView(gameView);
RelativeLayout.LayoutParams adParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
layout.addView(adView, adParams);
setContentView(layout);
}
请帮忙,我不知道应该改变什么。
答案 0 :(得分:0)
您的错误消息是:
Could not find class 'com.google.android.gms.ads.AdView', referenced from method com.louu.aimproject.MainActivity.onCreate
这意味着com.google.android.gms.ads.AdView类尚未添加到您的APK中。该课程包含在Google Play服务库中,因此请确保将其添加到您的项目中。