gpt4 book ai didi

java - LeadBolt 广告集成到 AndEngine

转载 作者:行者123 更新时间:2023-12-02 07:42:30 25 4
gpt4 key购买 nike

我正在尝试将 Leadbolt“应用广告”和“应用通知”集成到我用 AndEngine 制作的游戏中。

当我开始游戏时,出现以下错误:

07-09 11:42:16.566: D/LBAdController(1262): org.json.JSONException: No value for notificationtype
07-09 11:42:16.566: D/LBAdController(1262): at org.json.JSONObject.get(JSONObject.java:354)
07-09 11:42:16.566: D/LBAdController(1262): at org.json.JSONObject.getString(JSONObject.java:510)
07-09 11:42:16.566: D/LBAdController(1262): at com.Leadbolt.AdController.setNotification(AdController.java:653)
07-09 11:42:16.566: D/LBAdController(1262): at com.Leadbolt.AdController.initialize(AdController.java:593)
07-09 11:42:16.566: D/LBAdController(1262): at com.Leadbolt.AdController.loadAd(AdController.java:1103)
07-09 11:42:16.566: D/LBAdController(1262): at ShogunArts.Tengu.TenguMain.onLoadEngine(TenguMain.java:152)
07-09 11:42:16.566: D/LBAdController(1262): at org.anddev.andengine.ui.activity.BaseGameActivity.onCreate(BaseGameActivity.java:61)
07-09 11:42:16.566: D/LBAdController(1262): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-09 11:42:16.566: D/LBAdController(1262): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-09 11:42:16.566: D/LBAdController(1262): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-09 11:42:16.566: D/LBAdController(1262): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-09 11:42:16.566: D/LBAdController(1262): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-09 11:42:16.566: D/LBAdController(1262): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 11:42:16.566: D/LBAdController(1262): at android.os.Looper.loop(Looper.java:123)
07-09 11:42:16.566: D/LBAdController(1262): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-09 11:42:16.566: D/LBAdController(1262): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 11:42:16.566: D/LBAdController(1262): at java.lang.reflect.Method.invoke(Method.java:521)
07-09 11:42:16.566: D/LBAdController(1262): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-09 11:42:16.566: D/LBAdController(1262): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-09 11:42:16.566: D/LBAdController(1262): at dalvik.system.NativeStart.main(Native Method)

还有

07-09 11:42:20.715: D/LBAdController(1262): java.lang.NullPointerException
07-09 11:42:20.715: D/LBAdController(1262): at android.view.ViewConfiguration.get(ViewConfiguration.java:211)
07-09 11:42:20.715: D/LBAdController(1262): at android.view.View.<init>(View.java:1814)
07-09 11:42:20.715: D/LBAdController(1262): at com.Leadbolt.AdController.displayAd(AdController.java:1393)
07-09 11:42:20.715: D/LBAdController(1262): at com.Leadbolt.AdController.access$2(AdController.java:1260)
07-09 11:42:20.715: D/LBAdController(1262): at com.Leadbolt.AdController$PollRequest.onPostExecute(AdController.java:2456)
07-09 11:42:20.715: D/LBAdController(1262): at com.Leadbolt.AdController$PollRequest.onPostExecute(AdController.java:1)
07-09 11:42:20.715: D/LBAdController(1262): at android.os.AsyncTask.finish(AsyncTask.java:417)
07-09 11:42:20.715: D/LBAdController(1262): at android.os.AsyncTask.access$300(AsyncTask.java:127)
07-09 11:42:20.715: D/LBAdController(1262): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
07-09 11:42:20.715: D/LBAdController(1262): at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 11:42:20.715: D/LBAdController(1262): at android.os.Looper.loop(Looper.java:123)
07-09 11:42:20.715: D/LBAdController(1262): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-09 11:42:20.715: D/LBAdController(1262): at java.lang.reflect.Method.invokeNative(Native Method)
07-09 11:42:20.715: D/LBAdController(1262): at java.lang.reflect.Method.invoke(Method.java:521)
07-09 11:42:20.715: D/LBAdController(1262): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-09 11:42:20.715: D/LBAdController(1262): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-09 11:42:20.715: D/LBAdController(1262): at dalvik.system.NativeStart.main(Native Method)
07-09 11:42:20.715: D/AdController(1262): Exception - null

我将以下代码添加到 onLoadEngine 方法内的主类中,并在 onLoadComplete 方法中对其进行了测试。

public Engine onLoadEngine() { / public void onLoadComplete() {
myController1 = new AdController(getApplicationContext(), "277481637");
myController1.setAsynchTask(true);
myController1.loadNotification();
myController2 = new AdController(getApplicationContext(), "497251530");
myController2.loadAd();
//MORE CODE
return engine;
}

我创建了一个 BootReceiver 类(我使用了正确的包名):

package <PackageName>;

import com.Leadbolt.AdController;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
public class BootReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context arg0, Intent arg1) {
//register the notification on reboot
AdController mycontroller = new AdController(arg0, "277481637");
mycontroller.loadNotification();
}

}

并将其添加到我的 list 中:

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name=".BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

也许有人可以帮助我。

最佳答案

经过审查,我发现您的代码中的这一行是错误的:

myController2 = new AdController(getApplicationContext(), "497251530");
myController2.loadAd();

无法传入广告的应用程序上下文,您需要传入 Activity。

还在您的 list 文件中包含以下行:

<receiver android:name="com.Leadbolt.AdNotification" />

此行需要出现在 list 文件中标记之前。

希望这对您有所帮助,如果您仍然遇到问题,可以随时通过 support@leadbolt.com 与我们联系

关于java - LeadBolt 广告集成到 AndEngine,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11394466/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com