1

I tried both admob and mobfox. However, there is no advertisement in list activity.

RelativeLayout adslayout;
adapter = new ArrayAdapter<String>(this,R.layout.listlayout,R.id.txtmesajlar , messages);
mobfoxView = new MobFoxView(this, publisherId, true, true);
setListAdapter(adapter);
adslayout = (RelativeLayout)findViewById(R.id.adslayout);
adslayout.addView(mobfoxView);

From Logcat: Exception is java lang NullPointerException.

When i tried same codes in my other activity, i put mobfoxview in linearlayout and ads banner succesfully added. Is listactivity ignore advertisement or there is some error from me?

listlayout.xml

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<RelativeLayout android:layout_height="wrap_content" android:id="@+id/adslayout" android:layout_width="fill_parent" android:layout_gravity="center"></RelativeLayout>
<TextView android:layout_height="wrap_content" android:id="@+id/txtmesajlar" android:layout_width="fill_parent" android:textColor="@color/White" android:textSize="18sp" android:textStyle="bold" android:drawingCacheQuality="auto" android:drawableLeft="@drawable/listenvelop"></TextView>
</LinearLayout>

LOGCAT

08-25 12:11:59.925: ERROR/AndroidRuntime(887): FATAL EXCEPTION: main 08-25 12:11:59.925: ERROR/AndroidRuntime(887): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mc.bayrammesajlari/com.mc.bayrammesajlari.BayramActivity}: java.lang.NullPointerException 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at android.os.Handler.dispatchMessage(Handler.java:99) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at android.os.Looper.loop(Looper.java:123) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at android.app.ActivityThread.main(ActivityThread.java:3683) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at java.lang.reflect.Method.invokeNative(Native Method) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at java.lang.reflect.Method.invoke(Method.java:507) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at dalvik.system.NativeStart.main(Native Method) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): Caused by: java.lang.NullPointerException 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at com.mc.bayrammesajlari.BayramActivity.onCreate(BayramActivity.java:52) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 08-25 12:11:59.925: ERROR/AndroidRuntime(887): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

Many thanks.

dunker
  • 97
  • 9

1 Answers1

1

If you want to put ads next to your list, the answers to this question explain how to do it (PreferenceActivity is just a subclass of ListActivity so the solution is the same).

If you want the ads to actually appear in the list (as rows that scroll with the rest of the list content), I previously wrote this article about how I achieved this for AdMob.

Community
  • 1
  • 1
Dan Dyer
  • 53,737
  • 19
  • 129
  • 165
  • I m confused. I have a one listlayout.xml which is used by here: adapter = new ArrayAdapter(this,R.layout.listlayout,R.id.txtmesajlar , mesajlar); listlayout.xml 's main element is linearlayout and it contains textview and relative layout. Do i need to add listview in it or i completely remove listlayout.xml and create new .xml which its main element is listview? – dunker Aug 25 '11 at 16:16
  • @Dunker If you define your own layout for the `ListActivity` it needs to include a `ListView` called `@android:id/list` so that Android knows where the list goes in relation to the other widgets (such as your ads). – Dan Dyer Aug 25 '11 at 16:23
  • Thank you for your support. I really attempt to solve. I created my own layout for listactivity design. Therefore, i do not use android's default list. However, i didn't create any listview but it works. All items list in properly. I created textview for list item's attributes like color, text size etc. I created relativelayout for holding advertisement. Therefore, why can i need to create listview for? I did something wrong but i can't solve. Clearly, textview defines listitem's color size and logo and advertisement fails in relativelayout. – dunker Aug 25 '11 at 16:40
  • I solve it. Thank you for your support but i wonder about something. I didn't create listview in layout but it works. I suppose if the objects strings, there is no problem but if the view is coming like ads it throws an exception. – dunker Aug 25 '11 at 19:04
  • It's difficult to understand exactly what you are/were doing from the incomplete code in the question. We may be referring to different layouts. If you put the ads *in* the list rather than next to the list then you wouldn't need a custom layout to hold your `ListView`, you'd only need the layout that is used to render each row. – Dan Dyer Aug 25 '11 at 19:07
  • Yes, i understand but i have a new problem. When i add ads in list, list's itemclick is disabled. İs there a way to use both of them's action in same layout? My actual aim is to put ads top in listactivity (not every single row). I think i use your class to do that. – dunker Aug 25 '11 at 20:01