我正在尝试将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();
}
}
并将其添加到我的清单中:
<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>
也许有人可以帮助我。