I'm still fairly new to programming.
I'm working on a practice app and it crashes whenever I try to run it. I've tried moving the main body of the code to different app templates and it still crashes. I tried putting it in place of code in a working app and it fails. I'm sure it is something in the code and can't wait to find out what. Thank you all in advance for your help.
-Joseph
Here is my 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:ignore="contentDescription">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/goliath2"
android:scaleType="centerCrop"
android:id="#+id/imageGoliath"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I'm Goliath."
android:textColor="#C62828"
android:textSize="36sp"
android:fontFamily="sans-serif-medium"
android:textStyle="bold"
android:id="#+id/ImGoliath"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:padding="12dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't be afraid, I don't bite..."
android:textSize="26sp"
android:fontFamily="sans-serif-medium"
android:textColor="#C62828"
android:id="#+id/afraid"
android:layout_below="#id/ImGoliath"
android:textStyle="bold|italic"
android:paddingLeft="12dp"
android:paddingBottom="18dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/unless"
android:text="Unless!"
android:textColor="#C62828"
android:textSize="52sp"
android:textStyle="bold"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#id/afraid"
android:padding="24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/Youreacricket"
android:text="YOU'RE A CRICKET!"
android:textColor="#C62828"
android:layout_alignParentBottom="true"
android:textSize="42sp"
android:textStyle="bold"
android:layout_centerInParent="true"
android:paddingTop="60dp"/>
It appears that my problem was likely an image file that was too large.
After replacing the image with the androidparty image I got during class the app ran fine.
Thank you all who tried to help.
Related
I am developping both on 7 inch screen and on an htc m8. I have many layout xml files that are running fine. I have one fragment that is creating the problem. I run it on my samsung 7 inch screen in landscape mode setup in manifest.
My tablet is running like a charm. Then I copy my large-land file in layout-land and try to run my code on the htc. I've done this method many times.
But here I get a crash when running inflater.inflate.
something must be wrong in the xml? the stack trace and my layout xml file is joined.
I'm stuck. any ideas?
I don't see any clues in the trace that points me to the issue.
I add the stack as jpg because something is not liked about my format by stackoverflow.
layout file:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="#color/LightSkyBlue"
tools:context="com.example.bernard.speechparole.Cards">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/title_cards_ex"
android:layout_centerHorizontal="true"/>
<ImageView
android:id="#+id/image"
android:layout_height="190dp"
android:layout_width="350dp"
android:layout_marginTop="30dp"
android:layout_below="#id/title_cards_ex"
android:layout_toRightOf="#+id/help"
android:layout_marginLeft="40dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/work_validation"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/pro_validation"
android:layout_below="#+id/title_cards_ex"
android:layout_marginTop="65dp"
android:layout_marginLeft="20dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/next"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/next"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/work_validation"
android:layout_alignBottom="#id/work_validation"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/help"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/help"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/next"
android:layout_alignBottom="#id/next"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/done"
android:textSize="40dp"
android:visibility="invisible"
android:text="#string/done"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/work_answer"
android:layout_below="#+id/work_validation"
android:textSize="30dp"
android:background="#drawable/round_corner"
android:layout_alignLeft="#+id/work_validation"
android:ems="7"
android:layout_marginTop="15dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/resp_card"
android:textSize="29dp"
android:textColor="#color/DarkBlue"
android:textStyle="bold"
android:id="#+id/resp_card"
android:layout_marginTop="40dp"
android:layout_alignLeft="#id/work_validation"
android:visibility="invisible"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/mem_report"
android:id="#+id/report_card"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_below="#id/work_answer"
android:layout_alignLeft="#id/work_validation"
android:layout_marginTop="25dp"/>
</RelativeLayout>
The issue is with one of your string or drawable resource. Check the id of the resource in the exception and search for it in R.java to figure out which resource is causing the problem or just see if something is highlighted in red in your XML.
So it works fine unless I try to make it fit in the center, then it makes my app crash whenever I run it. I tried changing the framelayout to a linearlayout but it still crashes. Any ideas on how to fix this?
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/horizontalScrollView"
android:layout_alignTop="#+id/current"
android:layout_alignBottom="#+id/current"
android:background="#drawable/wood_background">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/recent_notes_list">
</LinearLayout>
</HorizontalScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/gen_note"
android:id="#+id/current"
android:singleLine="true"
android:textStyle="bold|italic"
android:typeface="sans"
android:layout_marginLeft="16sp"
android:alpha=".75"
android:gravity="center_vertical|center_horizontal"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="false" />
<Button
android:layout_width="35sp"
android:layout_height="match_parent"
android:text="#string/previous_txt"
android:id="#+id/previous"
android:layout_centerVertical="true"
android:layout_alignParentStart="false"
android:layout_below="#+id/horizontalScrollView"
android:textSize="30sp"
android:textStyle="bold"
android:layout_alignParentLeft="false"
android:layout_alignParentEnd="false"
android:alpha=".5" />
<Button
android:layout_width="35sp"
android:layout_height="match_parent"
android:text="#string/next_button"
android:id="#+id/next"
android:layout_centerVertical="true"
android:layout_alignParentStart="false"
android:layout_below="#+id/horizontalScrollView"
android:textSize="30sp"
android:textStyle="bold"
android:layout_alignParentLeft="false"
android:layout_alignParentEnd="false"
android:alpha=".5"
android:singleLine="false"
android:layout_alignParentRight="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_alignStart="#+id/current"
android:layout_marginLeft="20sp"
android:layout_marginRight="33sp"
android:layout_below="#+id/horizontalScrollView"
android:background="#drawable/parchment_back"></LinearLayout>
Project -> Clean
Sometimes it helps
Weird.. I guess it's only crashing if I assign a background image... The funny thing is, this is sorta why I'm using a frame layout anyways (to layer things).. That SORTA fixes my problem I guess.
Nope, never mind. I guess for some reason android doesn't like my parchment texture. I kind of don't need it anyways so I just deleted it.
This is probably the weirdest thing it ever happened to me. I inherit this code from another developer and I can't figure out which is the problem.
The app uses the sherlocknabvar and it also has a screen with a mapfragment where you can move a pin around and once the map is settled it calls several APIs to get some info about your position. The rest of the activities are pretty normal, nothing fancy about them. The map activity is quite complex though.
This is the error I have... weirdest thing is that it only happens sometimes, so it's not easy to reproduce it but I still can see it happen from time to time.
After playing with the map for a while (moving the pin, zooming in and out and so on) if I go back to the main activity (by clicking a home button on the navbar or by clicking the back button) all the texts in my app are gone in all the activities. I can see all the different layouts with images and colours but all the texts are completely gone. The only way to have them back is by restarting the app.
Looking at the Android Device Monitor (in case was some memory leak) everything looked pretty stable (28016K/33287K as max) and even worst, I can reproduce that error in an old Sony Xperia but also in a new brand S5.
EDIT
I found out that the texts where not missing, the color was changing to transparent for some reason that I still don't get. I disabled the hardware acceleration and it works but I'm still wondering what the problem could be and why that changed fixed it.
This is one of the layouts I'm having problems with, all the TextViews just change to transparent without any reason. It happens to the TextViews that have an 'static' text and also to the ones that I change the text dynamically.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="#drawable/new_bg_background_app"
>
<ScrollView
android:layout_alignParentTop="true"
android:layout_above="#+id/anc_button"
android:fadeScrollbars="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/anc_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="25dp"
android:gravity="center"
android:text="#string/lb_confirmed"
android:textColor="#color/orange"
android:textAppearance="#style/Font50PX"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ic_confirmed"
android:layout_marginTop="15dp"
android:src="#drawable/new_ic_active"
android:layout_below="#+id/anc_title"
android:layout_centerHorizontal="true" />
<TextView
android:id="#+id/lb_pick_up"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:layout_below="#+id/ic_confirmed"
android:text="#string/lb_your_pick_up"
android:textAppearance="#style/Font28PX"
android:textColor="#color/text_gray" />
<TextView
android:id="#+id/txt_passengers"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_below="#+id/lb_pick_up"
android:text="5 Passengers"
android:textAppearance="#style/Font50PX"
android:textColor="#color/white"/>
<TextView
android:id="#+id/lb_from"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="6dp"
android:layout_below="#+id/txt_passengers"
android:text="#string/lb_from"
android:layout_marginTop="15dp"
android:textAppearance="#style/Font28PX"
android:gravity="center"
android:textColor="#color/text_gray" />
<TextView
android:id="#+id/txt_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="60"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center"
android:layout_below="#+id/lb_from"
android:textAppearance="#style/Font50PX"
android:textColor="#color/white"
/>
<TextView
android:id="#+id/txt_post_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="60"
android:gravity="center"
android:layout_below="#+id/txt_address"
android:textAppearance="#style/Font45PX"
android:textColor="#color/text_gray"
/>
<TextView
android:id="#+id/lb_at"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_post_code"
android:text="#string/lb_at"
android:layout_marginTop="15dp"
android:textAppearance="#style/Font28PX"
android:gravity="center"
android:textColor="#color/text_gray" />
<TextView
android:id="#+id/txt_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_below="#+id/lb_at"
android:textAppearance="#style/Font50PX"
android:text="9:00 AM Today"
android:textColor="#color/white"
/>
<TextView
android:id="#+id/txt_note"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_time"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="#string/lb_mini"
android:textAppearance="#style/Font26PX"
android:textColor="#color/text_gray"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txt_note"
android:layout_marginTop="10dp"
android:gravity="center"
>
<TextView
android:id="#+id/lb_reference"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/lb_reference"
android:layout_marginTop="15dp"
android:textAppearance="#style/Font32PX"
android:textColor="#color/white"
/>
<TextView
android:id="#+id/txt_reference"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/lb_reference"
android:layout_marginLeft="4dp"
android:layout_marginTop="17dp"
android:textAppearance="#style/Font28PX"
android:textColor="#color/white"
/>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
<Button
android:id="#+id/anc_button"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:text="#string/lb_done"
android:background="#drawable/new_btn_orange"
android:layout_margin="5dp"
android:onClick="onDone"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>
This issue was fixed after disabling the hardware acceleration in the manifest just for the activity I was having the problem with
android:hardwareAccelerated="false"
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
I just set up a background for this app I'm making, but now it won't run. It was working before I assigned the background. I was wondering if someone could help me with this. Maybe I'm supposed to have some java code with it as well?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backgroundhdpi" >
<EditText
android:id="#+id/bill"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="100dp"
android:ems="10"
android:inputType="phone"
android:text="Enter Your Bill"
android:textSize="18dip" />
<Button
android:id="#+id/calculateTip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/bill"
android:layout_alignParentBottom="true"
android:layout_marginBottom="40dp"
android:layout_marginLeft="15dp"
android:text="Calculate" />
<TextView
android:id="#+id/tipOwed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bill"
android:layout_centerHorizontal="true"
android:layout_marginBottom="123dp"
android:scrollHorizontally="false"
android:text="Time to Tip"
android:textColor="#2c6f37"
android:textSize="35dip"
android:textStyle="bold" />
</RelativeLayout>
As long as the background is in res/drawable it shouldn't cause any crashing issues. There is no Java that needs to be associated with setting a background that way. Is there an error in the logcat?
(I would leave this as a comment but I don't have enough rep to do so)