我跟着LIBGDX關於建立AdMob的教程:https://github.com/libgdx/libgdx/wiki/Admob-in-libgdx錯誤設置AdMob後LIBGDX
和我的 「AndroidLauncher.java」 目前看起來是這樣的:
package com.theashcode.hfcytGame.android;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.android.gms.ads.*;
import com.theashcode.hfcytGame.Game;
public class AndroidLauncher extends AndroidApplication {
AdView adView;
View gameView;
@Override public void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
// Create the layout
RelativeLayout layout = new RelativeLayout(this);
// Do the stuff that initialize() would do for you
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Create the libgdx View
gameView = initializeForView(new Game(), config);
----線造成問題 - ----
// Create and setup the AdMob view
adView = new AdView(this, AdSize.BANNER, "ca-app- pub-000000000000");// Put in your secret key here
adView.loadAd(new AdRequest());
----行的結束導致的問題------
// Add the libgdx view
layout.addView(gameView);
// Add the AdMob view
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);
// Hook it all up
setContentView(layout);
}
}
正如我指出的,我在這條線
// Create and setup the AdMob view
adView = new AdView(this, AdSize.BANNER, "ca-app- pub-000000000000");
adView.loadAd(new AdRequest());
得到一個錯誤就可以了說,第一行的「構造函數的AdView(AndroidLauncher,adSize時,字符串)是未定義
而在第二行它說
- 「在類型的AdView的方法loadAd(com.google.android.gms.ads.AdRequest)不適用於參數(com.google.ads.AdRequest)
- 「構造的AdRequest()是不可見的」
如果有人可以幫助我,我就明白了很多,謝謝。我對libGDX頗爲陌生。
謝謝,libs文件夾中有唯一的「谷歌播放服務。 jar「,我只有這些類現在導入:import com.google.android.gms.ads。在AdRequest; import com.google.android.gms.ads.AdSize; import com.google.android.gms.ads.AdView; 但是我仍然得到錯誤。謝謝您的幫助。 – Ash 2014-10-04 21:37:59