Error when inflating my layout file - android

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.

Related

Overlapping a button on an image

I want to overlap 10 buttons on an image. I am using RelativeLayout to do the same but as a result, the position of the buttons changes in different devices. So, can someone tell me a workaround for that? This is the xml file for this activity:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/exercise1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="5dp"
tools:context="nmss.example.com.coach.Exercise1">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/humanbody"
android:layout_marginStart="20dp"/>
<Button
android:id="#+id/btn_neck"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginStart="145dp"
android:layout_marginTop="62dp"
android:text="Neck"
android:textSize="12sp" />
<Button
android:id="#+id/btn_shoulder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="35dp"
android:layout_marginTop="75dp"
android:text="Shoulder"
android:textSize="12sp"/>
<Button
android:id="#+id/btn_biceps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
android:layout_marginTop="135dp"
android:text="Biceps"
android:textSize="12sp"/>
<Button
android:id="#+id/btn_forearm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
android:layout_marginTop="195dp"
android:text="Forearm"
android:textSize="12sp"/>
<Button
android:id="#+id/btn_quads"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="68dp"
android:layout_marginTop="315dp"
android:text="Quads"
android:textSize="12sp"/>
<Button
android:id="#+id/btn_chest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="145dp"
android:layout_marginTop="100dp"
android:text="Chest"
android:textSize="12sp"/>
<Button
android:id="#+id/btn_abs"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:layout_marginStart="150dp"
android:layout_marginTop="160dp"
android:text="Abs"
android:textSize="12sp"/>
<Button
android:id="#+id/btn_triceps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="246dp"
android:layout_marginTop="125dp"
android:text="Triceps"
android:textSize="12sp" />
<Button
android:id="#+id/btn_mid_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="215dp"
android:layout_marginTop="175dp"
android:text="Middle back"
android:textSize="12sp"/>
<Button
android:id="#+id/btn_calves"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="210dp"
android:layout_marginTop="400dp"
android:text="Calves"
android:textSize="12sp"/>
</RelativeLayout>
This is the view in Android Studio
Just use LinearLayout instead of RelativeLayout.
Try to arrange your image buttons on top,bottom,right and left using the percentages.
You also need to create different Layouts Folders in your res folder for all devices and use the dimensions accordingly.
Never hard code the sizes like this, 25dp,
Add this link to your dependencies, to get the dimensions for every screen.
compile 'com.intuit.sdp:sdp-android:1.0.4'
Its uses is like this,
android:layout_marginTop="#dimen/_110sdp"
After writing, #dimen/...Ctrl+Space, you can see the value of dimensions from 1dp to 600dp. Try it, its very useful.

App shows no errors but crashes

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.

RelativeLayout displays incorrect on real device

I have a question regarding Android RelativeLayout. My layout works perfectly on the emulator which is configured like a LG Nexus4 (screen, resolution). But if I run the app on my real Nexus4 it has serious errors and I don't know how to fix them.
Here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainMenuLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/zeekedLogo"
android:contentDescription="#string/logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="24dp"
android:layout_marginRight="24dp"
android:src="#drawable/badge" />
<TextView
android:id="#+id/textButtonPlay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="56dp"
android:text="#string/menu_play"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textButtonResume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textButtonPlay"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="#string/menu_resume"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textLabelLevel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/zeekedLogo"
android:layout_centerHorizontal="true"
android:layout_marginBottom="54dp"
android:text="#string/menu_level"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textButtonSound"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/zeekedLogo"
android:layout_marginLeft="24dp"
android:text="#string/menu_sound_on"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
Here are the screenshots of the same layout:
Emulator:
Nexus 4:
Thanks in advance!
After adding a background color to my relativelayout it worked on my Nexus4. It's all I did ... and I think it's strange. But at the end I'm happy that it works.

How to define two different layouts for the layouts in the same category but slightly different inches?

I am testing my layout in eclipse's graphical layout. There are 5.4in FWVGA(480x854,mdpi) and 5.1in WVGA(480x800,mdpi) screens available to view in the graphical layout. If I am correct they both fall into large screen category, therefore I've put the layout xml into layout-large folder. And I've put my images into drawable-large-mdpi folder. But the image buttons are slightly off in 5.1in WVGA as you can see in the screenshots below. First is 5.1in, the second screenshot is 5.4'' and the correct one.
My second question which is similar to the above goes like this. I've done new layout for the Nexus 7 and put it into layout-sw600dp folder, and images to the drawable-tvdpi. Then I viewed this layout in the 7in tablet (1024x600,mdpi). And the image buttons are slightly off than it should look. The same way as in the first question.
I understand that the reason is probably because 5.1in and 5.4in isn't exactly the same even though they fall into the same category and I should have 2 different layouts for them. So how I should go about it? How can I have two different layouts? Or is there better solution, as I don't want to create a layout for each screen size that exist on the market.
Here is xml file:
<?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/wall4_cabinetclosed" android:orientation="vertical">
<RelativeLayout android:id="#+id/frames_layout"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="73dp" android:layout_marginTop="57dp">
<ImageView android:id="#+id/fire_frame"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
android:background="#drawable/small_fire_icon" />
<ImageView android:id="#+id/water_frame"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#+id/fire_frame" android:layout_marginLeft="75dp"
android:layout_toRightOf="#+id/fire_frame" android:background="#drawable/small_water_icon" />
<ImageView android:id="#+id/earth_frame"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="#+id/fire_frame" android:layout_marginTop="71dp"
android:layout_toLeftOf="#+id/water_frame" android:background="#drawable/small_earth_icon" />
<ImageView android:id="#+id/wind_frame"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignLeft="#+id/water_frame" android:layout_alignTop="#+id/earth_frame"
android:background ="#drawable/small_wind_icon" />
</RelativeLayout>
<ImageView android:id="#+id/zoomed_image"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:id="#+id/frames" android:layout_width="210dp"
android:layout_height="220dp" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:layout_marginLeft="55dp"
android:layout_marginTop="30dp" android:onClick="zoomFrames"
android:background="#android:color/transparent"/>
<Button android:id="#+id/blue" android:layout_width="115dp"
android:layout_height="70dp" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:layout_marginLeft="220dp"
android:onClick="zoomImage"
android:background="#android:color/transparent"/>
<Button android:id="#+id/white" android:layout_width="85dp"
android:layout_height="50dp" android:layout_alignParentRight="true"
android:layout_alignParentTop="true" android:layout_marginRight="420dp"
android:layout_marginTop="420dp" android:onClick="zoomImage"
android:visibility="invisible"
android:background="#android:color/transparent"/>
<ImageView
android:id="#+id/fireplace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="311dp"
android:layout_marginLeft="67dp"
android:background="#drawable/fire"
/>
<ImageButton
android:id="#+id/water_room"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="310dp"
android:layout_marginLeft="90dp"
android:background="#drawable/view_water_room"
android:onClick="finishFireRoom"
android:visibility="gone"
/>
<ImageView android:id="#+id/frames_zoomed_image"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#drawable/frames_zoomed" android:onClick="hideZoomedFrames"
android:visibility="gone"/>
<RelativeLayout android:id="#+id/frameZoomedLayout"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="113dp" android:layout_marginLeft="145dp"
android:visibility="gone"
>
<ImageButton android:id="#+id/fire_icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#drawable/fire_icon" android:onClick="changeIcon" />
<ImageButton android:id="#+id/water_icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="#+id/fire_icon" android:layout_toRightOf="#+id/fire_icon"
android:background="#drawable/water_icon" android:layout_marginLeft="147dp" android:onClick="changeIcon"/>
<ImageButton android:id="#+id/earth_icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="#+id/fire_icon" android:layout_marginTop="140dp"
android:layout_toLeftOf="#+id/water_icon" android:background="#drawable/earth_icon" android:onClick="changeIcon"/>
<ImageButton android:id="#+id/wind_icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignLeft="#+id/water_icon" android:layout_alignTop="#+id/earth_icon"
android:background="#drawable/wind_icon" android:onClick="changeIcon"/>
</RelativeLayout>
</RelativeLayout>
in 3rd step set all ur device specific like screen, language etc all. and ur done

I Made A Background For my App, But Now It Won't Run

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)

Categories

Resources