I have added admob codes for showing ads in my app. When i run the app in emulator it opens the splash screen and then the app suddenly exits saying "Unfortunately,Your app has stopped". I don't know why it is showing. It works well before addding the admob codes.I have also added the code. help me with this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"``
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background2" >
<ScrollView
android:id="#+id/scrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="60dp"
android:background="#null"
android:padding="30dp"
android:src="#drawable/menu1"
android:contentDescription="#string/image_desc" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageButton1"
android:background="#null"
android:padding="30dp"
android:src="#drawable/menu2"
android:contentDescription="#string/image_desc" />
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageButton2"
android:background="#null"
android:padding="30dp"
android:src="#drawable/menu3"
android:contentDescription="#string/image_desc" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageButton3"
android:background="#null"
android:padding="30dp"
android:src="#drawable/menu4"
android:contentDescription="#string/image_desc" />
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageButton4"
android:background="#null"
android:padding="30dp"
android:src="#drawable/menu5"
android:contentDescription="#string/image_desc" />
</LinearLayout>
</ScrollView>
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="admob id"
ads:adSize="SMART_BANNER"
ads:loadAdOnCreate="true"/>
</RelativeLayout>
there might be a some problem with adding googleadmobsdk cross check yourself with this link visit https://developers.google.com/mobile-ads-sdk/docs/#android.
I think that i can find at least one problem in your application, you are missing one impotant field in your admob specification, you must add that line in your layout:
ads:adUnitId="yourunitid"
In order to obtain yout unit id you must register your app to admob site, here: http://www.admob.com/my_sites/create_site
Another thing that you must consider, is that if you had just inserted the app, the banners usually show only after few hours.
Finally, i suggest you to add that line in your layout:
ads:testDevices="TEST_EMULATOR"
With that you are saying to admob to send only "test" banner to your device (this prevent the risk to be banned)
So your adView should be like:
then if it doesn't help add your logcat output.
Related
I got a realy annoying Problem with adMob and his banner sizes.
The smart banner size is a realy good thing, it does almost anything for you, what has to do with sizing ads, but only almost..
In the google docs is a table which sizes the smartbanner supports.
There are many sizes supported but not the landscape from a normal android phone..
https://developers.google.com/mobile-ads-sdk/android-legacy/docs/admob/smart-banners
Thats how it looks like now:
Portrait - all good
Landscape - dont work
So is there a way to display my ad in landscape at the right way?
(this is for the ads:adSize="SMART_BANNER", when i use ads:adSize="BANNER" it display on both but its locked to the size that ads:adSize="BANNER" is giving you, so it look terrible on bigger screens)
XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#color/main_bg_color"
android:id="#+id/rel_bg_home">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
android:layout_centerInParent="true"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
android:textSize="50sp"
android:id="#+id/uber"
android:shadowColor="#000000"
android:shadowRadius="5"
android:textStyle="bold"
android:textColor="#color/text_color"
android:layout_gravity="center_horizontal"
android:layout_weight="0.20"
android:gravity="center|bottom" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom|center_horizontal"
android:layout_weight="0.30"
android:gravity="bottom">
<Button
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Play"
android:id="#+id/play"
android:textColor="#color/text_color"
android:layout_marginBottom="20dp" />
<Button
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Help"
android:id="#+id/help"
android:textColor="#color/text_color"
android:layout_below="#+id/play"
android:layout_marginBottom="20dp" />
<Button
android:layout_width="90dp"
android:layout_height="wrap_content"
android:text="Score"
android:textColor="#color/text_color"
android:id="#+id/score" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_action_achievement"
android:layout_alignParentLeft="true"
android:layout_alignBottom="#+id/toggle"
android:layout_alignTop="#+id/toggle"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:id="#+id/highscore"/>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/toggle"
android:minHeight="10dp"
android:minWidth="10dp"
android:background="#drawable/check"
android:layout_alignParentRight="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:textOn=""
android:textOff=""
android:layout_marginRight="#dimen/activity_horizontal_margin"
android:layout_above="#+id/adView" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/banner_ad_unit_id1">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
Try to remove any margin or padding attribute from parent view in the xml file.
Hope this help you.
Sometimes smart_banner is not working in landscape mode. So change its size
ads:adSize="BANNER"
Perhaps this open-source solution can help you: https://github.com/ombori/app-banner
either by this:
npm install --save app-banner
var appBanner = require('app-banner');
// - or -
import appBanner from 'app-banner';
appBanner.init({
apple: 'id1234567890',
google: 'com.youcompany.yourapp',
placement: 'bottom-left',
})
or this:
npm install --save app-banner
import AppBanner from 'app-banner/src';
...
<div>
<AppBanner google="com.youcompany.yourapp" apple="id1234567890"
position="bottom-left" />
</div>
sorry for my english.
I made my first app very simple (web view with splash screen) for try and understand something basic function of android programming.
But when I build app-debug (directly on my smartphone), facebook start to crash continually.
I tried to leave only basic structure, commenting the rest
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
but, facebook continue to crash.
This is the log.
Someone can help me about this funny/annoyng issue?
This is activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<WebView
android:id="#+id/webView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="0dp"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/sad_android"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_margin="80dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageViewSplash"
android:src="#drawable/splash"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
/>
In the graphical view of layout, when I choose API 15 or lower from the button shown in the image below, the text in the encircled buttons looks fine.
When I choose API 17, the text is displaced even though the xml code is same. Changing the button padding does not help.
Is this just a problem with Eclipse or is it possible that new versions of android may see this displaced text?
What's the workaround to fix this?
XML code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeActivity" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_margin="3dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:src="#drawable/label" />
</LinearLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/linearLayout1"
android:layout_below="#+id/linearLayout1"
android:layout_marginTop="20dp"
android:text="#string/about_title"
android:textSize="20sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_alignRight="#+id/linearLayout1"
android:layout_below="#+id/textView1"
android:layout_marginTop="5dp"
android:text="#string/temp" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_alignRight="#+id/textView2"
android:layout_below="#+id/textView2"
android:layout_marginTop="20dp"
android:baselineAligned="false" >
<Button
android:id="#+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/news" />
<Button
android:id="#+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/tournaments" />
<Button
android:id="#+id/button3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/results" />
</LinearLayout>
android:gravity="center" did not help
I restarted eclipse twice. Strangely it did not help in the first restart but it looked fine after the second one. Also, its working fine on device.
Apologies for the question, I must have waited before posting the question.
Not sure if the default style for Buttons changed in API17... possibly...
Anyway, adding android:gravity="center" should be fixing this for you.
i don't know i faced this problem check restart a eclipse.. and check..
adding android:gravity="center" should be fixing this for you
The strangest thing happened to me today and caused hours of frustration and anger-management issues.
I had a working Android slideshow application. However, I was unhappy with the buttons (which were in a Relative Layout), and moved them to a Linear Layout. However, when running my application, the behavior of the buttons got swapped around (ie Button 1 did Button 2's work and vice-versa). I was able to remedy this by changing the id of ONE of the buttons, not all (that didn't work). Also related to this, was that my application started crashing when I switched orientation. It had worked previously when I had the Relative Layout. (I am using a Handler to change the UI for the slideshow)
I was unable to solve this issue, so I reverted to my Relative Layout, but I would like to know how this could have happened in the first place.
The layout that works:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:contentDescription="#string/imageView"
android:scaleType="centerInside"
android:src="#drawable/image1" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageButton
android:id="#+id/startStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/startStop"
android:src="#drawable/ic_menu_slideshow" />
<ImageButton
android:id="#+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="false"
android:layout_toRightOf="#+id/startStop"
android:contentDescription="#string/next"
android:src="#drawable/ic_media_next" />
<ImageButton
android:id="#+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="false"
android:layout_toLeftOf="#+id/startStop"
android:contentDescription="#string/previous"
android:src="#drawable/ic_media_previous" />
</RelativeLayout>
The code that causes problems:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:contentDescription="#string/imageView"
android:scaleType="centerInside"
android:src="#drawable/image1" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#30eee9e9" >
<ImageButton
android:id="#+id/previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/previous"
android:src="#drawable/ic_media_previous" />
<ImageButton
android:id="#+id/bla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/startStop"
android:src="#drawable/ic_menu_slideshow" />
<ImageButton
android:id="#+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/next"
android:src="#drawable/ic_media_next" />
I had the same problem but with Relative Layout as parent & Linear Layout as child layout I took four imagebuttons
PLAY
SCORE
HELP
QUIT
And buttons functionality was shifted to one below next i.e. when I pressed PLAY nothing happened when pressed SCORE Game started playing when clicked HELP showed me score and so on.. I put my whole night for solving the problem but nothing happened I shutted off dam thing tried to watch movie but for a while I was getting boared watching it I started Eclipse again and the magic that it was working so fine. Dont know But Rebuild & Clean has solved my problem as DeeV said
hi i just fixed the issue i had with
my application, now i am stuck with
another problem, please help :)
most of my code is here
"unknown Exception android"
now i want to make my main page look like this as shown in iphone
application given below,
"http://wwwm.coventry.ac.uk/app/Pages/iPhoneApp.aspx"
i dont know if i need to use tab activity or option menu or inflator,
as for call, email and web, i will have to call services as far as i
know.
and last if i can see any tutorial or code which will help me to solve my
problem, please give me a link.
thanks alot**
Main.xml looks like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<AbsoluteLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="#+id/AbsoluteLayout01">
<TextView android:layout_x="61dip" android:layout_y="176dip" android:id="#+id/TextView02" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="#string/courses"></TextView>
<ImageButton android:id="#+id/CoursesButton" android:layout_x="62dip" android:layout_y="107dip" android:background="#drawable/a" android:layout_height="65dp" android:layout_width="65dp"></ImageButton>
<TextView android:gravity="center" android:textSize="25dp" android:layout_height="wrap_content" android:layout_width="fill_parent" android:text="#string/LabelNescot" android:layout_x="1dip" android:layout_y="39dip" android:id="#+id/TextView"></TextView>
<ImageButton android:id="#+id/ILoveNescotButton" android:background="#drawable/b" android:layout_height="65dp" android:layout_width="65dp" android:layout_x="179dip" android:layout_y="106dip"></ImageButton>
<ImageButton android:id="#+id/GettingHereButton" android:background="#drawable/d" android:layout_height="65dp" android:layout_width="65dp" android:layout_x="185dip" android:layout_y="208dip"></ImageButton>
<TextView android:id="#+id/TextView05" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="#string/Directions" android:layout_x="182dip" android:layout_y="283dip"></TextView>
<TextView android:id="#+id/TextView03" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="#string/facility" android:layout_x="180dip" android:layout_y="177dip"></TextView>
<ImageButton android:background="#drawable/c" android:id="#+id/CampusMapButton" android:layout_height="65dp" android:layout_width="65dp" android:layout_x="48dip" android:layout_y="208dip"></ImageButton>
<TextView android:text="#string/Map" android:layout_height="wrap_content" android:id="#+id/TextView04" android:layout_width="wrap_content" android:layout_x="37dip" android:layout_y="285dip"></TextView>
</AbsoluteLayout>
z
</LinearLayout>
Hello Tab Layout.