일 동안 내 프로젝트에 광고를 추가하는 방법을 알아 내려고 노력했습니다. 너희들이 나에게 무엇을해야하는지 보여 줄 수 있기를 바란다. 첫 번째 라운드가 끝나면 광고를 게재하려고합니다 (처음 플레이어가 사망 함). 그것은 그들이 다시 게임을하도록 허락 할 것입니다.무엇이 잘못 되었나요? 삽입 광고를 추가하는 방법
어떤 광고가 표시되지 않고 I는 다음과 같은 오류를 얻고있다 :
09-02 17:14:53.825: W/dalvikvm(635): threadid=11: thread exiting with uncaught exception (group=0x40a13300)
09-02 17:14:53.835: E/AndroidRuntime(635): FATAL EXCEPTION: GLThread 75
09-02 17:14:53.835: E/AndroidRuntime(635): java.lang.NullPointerException
09-02 17:14:53.835: E/AndroidRuntime(635): at com.JrodManU.LaserJumper.android.Ad.loadAd(Ad.java:45)
09-02 17:14:53.835: E/AndroidRuntime(635): at com.JrodManU.LaserJumper.android.AndroidLauncher.loadAd(AndroidLauncher.java:26)
09-02 17:14:53.835: E/AndroidRuntime(635): at com.JrodManU.LaserJumper.LaserJumper.loadAd(LaserJumper.java:36)
09-02 17:14:53.835: E/AndroidRuntime(635): at com.JrodManU.LaserJumper.screens.InGameScreen. <init>(InGameScreen.java:51)
09-02 17:14:53.835: E/AndroidRuntime(635): at com.JrodManU.LaserJumper.LaserJumper.create(LaserJumper.java:15)
09-02 17:14:53.835: E/AndroidRuntime(635): at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:236)
09-02 17:14:53.835: E/AndroidRuntime(635): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1505)
09-02 17:14:53.835: E/AndroidRuntime(635): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
내 클래스 :
AndroidLauncher
package com.JrodManU.LaserJumper.android;
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.JrodManU.LaserJumper.GameEventListener;
import com.JrodManU.LaserJumper.LaserJumper;
public class AndroidLauncher extends AndroidApplication implements GameEventListener {
Ad ad = new Ad();
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
initialize(new LaserJumper(this), config);
}
@Override
public void showAd() {
ad.showAd();
}
@Override
public void loadAd() {
ad.loadAd();
}
@Override
public boolean isShowing() {
return ad.isShowing();
}
@Override
public boolean isLoaded() {
return ad.isLoaded();
}
}
InGameScreen (Screen 클래스)
package com.JrodManU.LaserJumper.screens;
import com.JrodManU.LaserJumper.LaserJumper;
public class InGameScreen implements Screen {
LaserJumper game;
boolean firstTime;
public InGameScreen(LaserJumper game) {
this.game = game;
game.loadAd();
firstTime = true;
}
@Override
public void render(float delta) {
generalUpdate();
}
private void generalUpdate() {
if(playerDied) {
if(firstTime && game.isLoaded()) {
System.out.println("hi");
game.showAd();
firstTime = false;
while(game.isShowing()) {
//Waiting for the ad to go away..
}
}
}
에이 D
package com.JrodManU.LaserJumper.android;
import com.JrodManU.LaserJumper.GameEventListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdListener;
import android.app.Activity;
import android.os.Bundle;
public class Ad extends Activity implements GameEventListener{
private InterstitialAd mInterstitialAd;
public static boolean showing;
public static boolean loaded;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("*****");
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
showing = false;
}
@Override
public void onAdLoaded() {
loaded = true;
}
});
}
public void showAd() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
showing = true;
}
}
public void loadAd() {
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
mInterstitialAd.loadAd(adRequestBuilder.build());
}
public boolean isShowing() {
if(showing) {
return true;
} else {
return false;
}
}
public boolean isLoaded() {
if(loaded) {
return true;
} else {
return false;
}
}
}
LaserJumper (기본 클래스)
package com.JrodManU.LaserJumper;
import com.JrodManU.LaserJumper.screens.*;
import com.badlogic.gdx.Game;
public class LaserJumper extends Game{
InGameScreen inGameScreen;
public Preferences preferences;
public GameEventListener gameEventListener;
@Override
public void create() {
inGameScreen = new InGameScreen(this);
setScreen(inGameScreen);
}
public void changeToInGame() {
inGameScreen = new InGameScreen(this);
setScreen(inGameScreen);
}
public LaserJumper(GameEventListener listener) {
gameEventListener = listener;
}
public void showAd() {
gameEventListener.showAd();
}
public void loadAd() {
gameEventListener.loadAd();
}
public boolean isShowing() {
return gameEventListener.isShowing();
}
public boolean isLoaded() {
return gameEventListener.isLoaded();
}
}
그리고 마지막으로,
package com.JrodManU.LaserJumper;
public interface GameEventListener {
public void showAd();
public void loadAd();
public boolean isShowing();
public boolean isLoaded();
}
어떤 줄이'com.JrodManU.LaserJumper.android.Ad.loadAd (Ad.java:45)'입니까? –
광고 클래스에서'loadAd()'메소드에 사용 된'mInterstitialAd' 객체가 생성되지 않은 것처럼 보입니다. onCreate 메소드가 실행되는지 확인하십시오. – Chedy2149