android - Nullpointer exception while adding the banner Ad -
i trying display banner ad in game using revmob display both banner ad , fullscreen ad. full screen ads displaying banner ad not displaying getting null poinet exception in view.addview(banner).
enter code herepublic class mainactivity extends activity { private ccglsurfaceview mglsurfaceview; private boolean iscreated = false; public static framelayout m_rootlayout; public static string application_id = "514c7c57cee0500d00000001"; public static revmob revmob; // used display toast messages , not necessary app @override protected void oncreate(bundle savedinstancestate) { if (!iscreated) { iscreated = true; } else { return; } super.oncreate(savedinstancestate); setrequestedorientation(activityinfo.screen_orientation_portrait); requestwindowfeature(window.feature_no_title); getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); setcontentview(r.layout.activity_main); revmob = revmob.start(this, application_id); displayrevmob(); mglsurfaceview = new ccglsurfaceview(this); setcontentview(mglsurfaceview); ccdirector.shareddirector().attachinview(mglsurfaceview); getscaledcoordinate(); global.assetmanager = getassets(); global.context = this; global.loaduserinfo(); ccscene scene = ccscene.node(); scene.addchild(new splashscene(), -1); ccdirector.shareddirector().runwithscene(scene); //-------------iap----------------------- log.d(tag1, "creating iab helper."); mhelper = new iabhelper(this, base64encodedpublickey); mhelper.enabledebuglogging(true); log.d(tag1, "starting setup."); mhelper.startsetup(new iabhelper.oniabsetupfinishedlistener() { public void oniabsetupfinished(iabresult result) { log.d(tag, "setup finished."); if (!result.issuccess()) { // oh noes, there problem. complain("problem setting in-app billing: " + result); return; } // hooray, iab set up. now, let's inventory of stuff own. log.d(tag, "setup successful. querying inventory."); mhelper.queryinventoryasync(mgotinventorylistener); } }); revmobbanner banner = revmob.createbanner(this); viewgroup view = (viewgroup) findviewbyid(r.id.banner); view.addview(banner); } public void displayrevmob(){ revmob.showfullscreen(this); } }
logcat:
04-20 14:05:53.591: e/androidruntime(1066): fatal exception: main 04-20 14:05:53.591: e/androidruntime(1066): java.lang.runtimeexception: unable start activity componentinfo{com.game.puzzlegame/com.game.puzzlegame.mainactivity}: java.lang.nullpointerexception 04-20 14:05:53.591: e/androidruntime(1066): @ android.app.activitythread.performlaunchactivity(activitythread.java:1956) 04-20 14:05:53.591: e/androidruntime(1066): @ android.app.activitythread.handlelaunchactivity(activitythread.java:1981) 04-20 14:05:53.591: e/androidruntime(1066): @ android.app.activitythread.access$600(activitythread.java:123) 04-20 14:05:53.591: e/androidruntime(1066): @ android.app.activitythread$h.handlemessage(activitythread.java:1147) 04-20 14:05:53.591: e/androidruntime(1066): @ android.os.handler.dispatchmessage(handler.java:99) 04-20 14:05:53.591: e/androidruntime(1066): @ android.os.looper.loop(looper.java:137) 04-20 14:05:53.591: e/androidruntime(1066): @ android.app.activitythread.main(activitythread.java:4424) 04-20 14:05:53.591: e/androidruntime(1066): @ java.lang.reflect.method.invokenative(native method) 04-20 14:05:53.591: e/androidruntime(1066): @ java.lang.reflect.method.invoke(method.java:511) 04-20 14:05:53.591: e/androidruntime(1066): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 04-20 14:05:53.591: e/androidruntime(1066): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 04-20 14:05:53.591: e/androidruntime(1066): @ dalvik.system.nativestart.main(native method) 04-20 14:05:53.591: e/androidruntime(1066): caused by: java.lang.nullpointerexception 04-20 14:05:53.591: e/androidruntime(1066): @ com.game.puzzlegame.mainactivity.oncreate(mainactivity.java:122) 04-20 14:05:53.591: e/androidruntime(1066): @ android.app.activity.performcreate(activity.java:4465) 04-20 14:05:53.591: e/androidruntime(1066): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1049) 04-20 14:05:53.591: e/androidruntime(1066): @ android.app.activitythread.performlaunchactivity(activitythread.java:1920) 04-20 14:05:53.591: e/androidruntime(1066): ... 11 more
xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <linearlayout android:id="@+id/banner" android:layout_width="wrap_content" android:layout_height="wrap_content" > </linearlayout> </linearlayout>
the problem in here:
viewgroup view = (viewgroup) findviewbyid(r.id.banner); view.addview(banner);
apparently findviewbyid()
returns null
, means view
called banner
not found in xml layout file.
you have r.layout.activity_main
set content view. ensure, have view
banner
id in file.
Comments
Post a Comment