Android cannot resolve R - android

This happened yesterday when i was replacing a few elements in my XML. When I went to my main class, I saw that all references to R had been marked red, and I was told that R could not be resolved to a variable. At first, I tried to rebuild and clean up my project, but that didn't work, so I am assuming that the issue lies in the XML file I recently edited, however I do now know where the issue would lie. And yes, I did make sure android.R was not being imported.
A few additional details:
I am using Android 5.0 (API 21)
The R issues do not appear in my other class files, which reference R.
Here is the XML file in question:
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_marginTop="20dp"
android:text="#string/rye"
android:textColor="#888888"
android:textAppearance="?android:textAppearanceLarge" />
<RatingBar
android:id="#+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView1"
android:layout_below="#+id/textView1"
android:isIndicator="false"
android:numStars="5"
android:stepSize="1" />
<Button
android:id="#+id/dropDownButton"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_alignBottom="#+id/ratingBar1"
android:layout_toRightOf="#+id/ratingBar1"
android:onClick="dropDown"
android:text=">"/>
<RelativeLayout
android:id="#+id/dropDownLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/textView2"
android:visibility="gone" >
<TextView
android:id="#+id/testTV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Testing dropdown" />
</RelativeLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tipTitle"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#888888"
android:layout_below="#+id/quizFragment"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<FrameLayout
android:id="#+id/quizFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/dropDownButton" />
<TextView
android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/people_dining_title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#888888"
android:layout_below="#+id/seekBar3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/subtotalTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/subtotal"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#888888"
android:layout_below="#+id/seekBar2"
android:layout_alignLeft="#+id/seekBar2"
android:layout_alignStart="#+id/seekBar2" />
<TextView
android:id="#+id/totalTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/subtotalText"
android:layout_below="#+id/subtotalText"
android:layout_marginTop="10dp"
android:text="#string/total"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#888888" />
<TextView
android:id="#+id/totalText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/subtotalText"
android:layout_alignRight="#+id/subtotalText"
android:layout_below="#+id/totalTitle"
android:focusable="false"
android:padding="2dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffff000c" />
<EditText
android:id="#+id/subtotalText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/subtotalTitle"
android:ems="10"
android:hint="SUBTOTAL"
android:inputType="numberDecimal"
android:padding="2dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ff0000"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/seekBar2"
android:layout_alignEnd="#+id/seekBar2">
</EditText>
<TextView
android:id="#+id/eppTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/totalText"
android:layout_below="#+id/totalText"
android:layout_marginTop="10dp"
android:text="#string/epp"
android:textColor="#888888"
android:textAppearance="?android:textAppearanceMedium" />
<TextView
android:id="#+id/eppText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/eppTitle"
android:layout_alignRight="#+id/totalText"
android:layout_below="#+id/eppTitle"
android:focusable="false"
android:padding="2dp"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
<Button
android:id="#+id/buttonDone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/eppText"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:onClick="done"
android:text="#string/done"
android:textStyle="bold" />
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/seekBar2"
android:layout_below="#+id/TextView02"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<SeekBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/seekBar3"
android:layout_below="#+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
</RelativeLayout>

I am not able to see any issues in this xml file . Can you also post the code for the class file where you are using it and check if you're not using android.r and using com.yourapp.r . This might be the case. Could you post the class also

Related

Android not finding View IDs

So I have a layout that I'm working on, and just to make sure everything is looking OK on an actual phone I'm doing a test run before I move on with the other labels. But, the problem is, Eclipse can only find one id contactName. The other id's all have an error saying that Android can't find them. My XML File is below:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/contactPicture"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="31dp"
android:layout_marginTop="34dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/nameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/contactPicture"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/contactPicture"
android:text="#string/name"
android:textSize="16sp"/>
<TextView
android:id="#+id/contactName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/nameLabel"
android:layout_below="#+id/nameLabel"
android:text="TextView"
android:textSize="20sp" />
<TextView
android:id="#+id/companyLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/companyName"
android:layout_alignLeft="#+id/companyName"
android:text="#string/company"
android:textSize="16sp" />
<TextView
android:id="#+id/companyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/contactPicture"
android:layout_alignLeft="#+id/contactName"
android:text="TextView"
android:textSize="20sp" />
<TextView
android:id="#+id/phoneLabel"
android:text="Phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/contactPicture"
android:layout_alignLeft="#+id/contactPicture"
android:layout_marginTop="30sp"
android:textSize="16sp"/>
<TextView
android:id="#+id/workNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Work Num"
android:textSize="20sp"
android:layout_below="#+id/phoneLabel"
android:layout_alignLeft="#+id/phoneLabel" />
<TextView
android:id="#+id/homeNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home Num"
android:textSize="20sp"
android:layout_below="#+id/workNum"
android:layout_alignLeft="#+id/workNum" />
<TextView
android:id="#+id/mobileNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile Num"
android:textSize="20sp"
android:layout_below="#+id/homeNum"
android:layout_alignLeft="#+id/homeNum" />
<TextView
android:id="#+id/workLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Work"
android:textSize="20sp"
android:layout_toRightOf="#+id/workNum"
android:layout_alignTop="#+id/workNum"
android:layout_marginLeft="120sp" />
<TextView
android:id="#+id/homeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home"
android:textSize="20sp"
android:layout_below="#+id/workLabel"
android:layout_alignLeft="#+id/workLabel" />
<TextView
android:id="#+id/mobileLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mobile"
android:textSize="20sp"
android:layout_below="#+id/homeLabel"
android:layout_alignLeft="#+id/workLabel" />
</RelativeLayout>
</ScrollView>

Minor changes in layout make the application to crash in Android.

I made an application for android, and it was loading fine in the emulator and phone, and then I made some minor changes like shifting the position of text View elements in the layout with help of "Graphical Layout" editing option in Eclipse. and after that the application no longer starts, it just loads with a blank activity and in 2-3 seconds crashes.
The layout that I am using looks like this currently (and this is the crashing state of layout):
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".BMI" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText1"
android:layout_alignLeft="#+id/textView2"
android:text="#string/weight"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_below="#+id/textView3"
android:layout_marginLeft="15dp"
android:layout_marginTop="30dp"
android:text="#string/button1_text" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_toRightOf="#+id/textView3"
android:ems="4"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText2"
android:layout_below="#+id/editText2"
android:ems="4"
android:inputType="numberDecimal" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_alignParentTop="true"
android:text="#string/bmi"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText2"
android:layout_alignParentTop="true"
android:text="#string/default_text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView4"
android:layout_marginLeft="17dp"
android:text="#string/height"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_toRightOf="#+id/editText1"
android:text="#string/button2_text" />
</RelativeLayout>
Try cleaning and rebuilding the project by going to "Project --> Clean..." then run the app again. After making changes in Eclipse to the layout, sometimes Eclipse doesn't "get" the changes right away so you end up with a goofy ClassCastException. A cleaning usually fixes this.
If this doesn't solve your problem then please post the logcat from the crash but this should do the trick.
I had several problems with Android build tool on both Eclipse and IntelliJ. Usually result in xml file doesn't get updated or shift up or down by a line or two. Usually, by rebuilding the project or restarting your IDE would fix this problem.
// try this
<?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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".BMI" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText1"
android:layout_alignLeft="#+id/textView2"
android:text="#string/weight"
android:textAppearance="#android:style/TextAppearance.Medium" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView3"
android:layout_below="#+id/textView3"
android:layout_marginLeft="15dp"
android:layout_marginTop="30dp"
android:text="#string/button1_text" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView2"
android:layout_toRightOf="#+id/textView3"
android:ems="4"
android:inputType="numberDecimal" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText2"
android:layout_below="#+id/editText2"
android:ems="4"
android:inputType="numberDecimal" >
</EditText>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_alignParentTop="true"
android:text="#string/bmi"
android:textAppearance="#android:style/TextAppearance.Medium" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText2"
android:layout_alignParentTop="true"
android:text="#string/default_text"
android:textAppearance="#android:style/TextAppearance.Medium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView4"
android:layout_marginLeft="17dp"
android:text="height"
android:textAppearance="#android:style/TextAppearance.Medium"/>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_toRightOf="#+id/editText1"
android:text="#string/button2_text" />
</RelativeLayout>

Trouble with graphical layout

When I am trying to look at my graphical layout this message appears in the error log:
activity_main.xml: Circular dependencies cannot exist in RelativeLayout.
How would I go about correcting this so my code will work correctly?
I have changed around the alignParentLeft and set them to true. I have also messed around with the align_above and align_below which hasn't helped. I'm not sure what my problem is.
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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="57dp"
android:text="Number of cups" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView1"
android:layout_marginRight="23dp"
android:layout_toRightOf="#+id/textView1"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<CheckBox
android:id="#+id/go"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/cream"
android:layout_alignParentLeft="true"
android:layout_marginBottom="20dp"
android:text="To Go" />
<CheckBox
android:id="#+id/cream"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/sugar"
android:layout_alignParentLeft="true"
android:layout_marginBottom="15dp"
android:text="Leave room for cream" />
<CheckBox
android:id="#+id/sugar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/drinks"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Leave room for sugar" />
<RadioGroup
android:id="#+id/drinks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/sugar"
android:layout_above="#+id/flavoring"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true" >
<RadioButton
android:id="#+id/coffee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coffee($2.50)" />
<RadioButton
android:id="#+id/cappuccino"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Cappucino($4.50)" />
<RadioButton
android:id="#+id/espresso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Espresso($4.50)" />
<RadioButton
android:id="#+id/latte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Latte($4.50)" />
<RadioButton
android:id="#+id/iced_latte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Iced Latte($5.00)" />
</RadioGroup>
<TextView
android:id="#+id/flavoring"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/chocolate"
android:layout_alignParentLeft="true"
android:layout_marginTop="57dp"
android:text="Flavoring" />
<CheckBox
android:id="#+id/chocolate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/cherry"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Chocolate" />
<CheckBox
android:id="#+id/cherry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/vanilla"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Cherry" />
<CheckBox
android:id="#+id/vanilla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/cherry"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Vanilla" />
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignLeft="#+id/editText1"
android:layout_alignParentBottom="true" >
</ScrollView>
</RelativeLayout>
These are your problems
<CheckBox
android:id="#+id/sugar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/drinks"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Leave room for sugar" />
<RadioGroup
android:id="#+id/drinks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/sugar"
android:layout_above="#+id/flavoring"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true" >
You are telling sugar to be above drinks and for drinks to be below sugar. You can only do one of these or they get into an infinite circle. So remove android:layout_below="#+id/sugar" from drinks RadioGroup.
I don't see yet if you have this anywhere else but if you do then you will need to fix those, also. You can't tell a View to be above another and tell that View to be below the same View...same with left and right.
Edit found another
<CheckBox
android:id="#+id/cherry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/vanilla"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Cherry" />
<CheckBox
android:id="#+id/vanilla"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/cherry"
android:layout_alignParentLeft="true"
android:layout_marginBottom="22dp"
android:text="Vanilla" />
You have the same thing going on here. You will need to remove the above or the below from one of these.

Create a listview with sides like older email android app

I want to create a listview like older gmail app. See the screenshot:
I tried putting an empty view like this:
<TextView
android:id="#+id/color_highlight"
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#ff0000"
android:minHeight="48dp" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#id/color_highlight"
android:text="Mudit Agarwal"
android:textStyle="bold"
android:textColor="#242424"
android:textIsSelectable="false"
android:textSize="22sp" />
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/name"
android:layout_below="#id/name"
android:text="9933445566"
android:textColor="#777777"
android:textIsSelectable="false"
android:layout_marginBottom="10dp"
android:textSize="15sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="3dp"
android:src="#drawable/contact" />
but this is not taking full height of the view. Please suggest.
What I changed is
android:layout_alignBottom="#+id/number"
to your color_highlight TextView. and instead of margin, I put padding like below in number TextView.
android:paddingBottom="20dp"
just put following layout code.
<?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="wrap_content" >
<TextView
android:id="#+id/color_highlight"
android:layout_width="5dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignBottom="#+id/number"
android:background="#ff0000"
android:minHeight="48dp" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_toLeftOf="#id/color_highlight"
android:text="Mudit Agarwal"
android:textColor="#242424"
android:textIsSelectable="false"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:id="#+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/name"
android:layout_below="#id/name"
android:paddingBottom="20dp"
android:text="9933445566"
android:textColor="#777777"
android:textIsSelectable="false"
android:textSize="15sp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:padding="3dp"
android:src="#drawable/contact" />
</RelativeLayout>
I'm not sure but you can try putting android:layout_height="0dip" instead of android:layout_height="match_parent".

Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12

Hi I am developing application .My application run perfectly on all devices.But when we run this application on mdpi phone its getting me this error:
Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x12.
Kindly help me where i am wrong.
This is My Code:-
<RelativeLayout
android:id="#+id/LevLayId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="140dp" >
<TextView
android:id="#+id/totlScorId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#drawable/score_timer"
android:gravity="center"
android:textColor="#ffffff" />
<TextView
android:id="#+id/levelId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/score_timer"
android:gravity="center"
android:textColor="#ffffff" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/LayAboButId"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/option_last_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="7px"
android:orientation="horizontal" >
<Button
android:id="#+id/opt3Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/option_normal_new"
android:gravity="center|center_vertical"
android:textColor="#ffffff"
android:textSize="11dp" />
<Button
android:id="#+id/opt4Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/option_normal"
android:gravity="center|center_vertical"
android:textColor="#ffffff"
android:textSize="11dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/option_pre_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/option_last_row"
android:layout_marginBottom="3px"
android:orientation="horizontal" >
<Button
android:id="#+id/opt1Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/option_normal_new"
android:gravity="center|center_vertical"
android:textColor="#ffffff"
android:textSize="11dp" />
<Button
android:id="#+id/opt2Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/option_normal"
android:gravity="center|center_vertical"
android:textColor="#ffffff"
android:textSize="11dp" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/imgLayId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginRight="#id/totlScorId"
android:layout_marginTop="70dp" >
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<ImageView
android:id="#+id/imgViewId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<ImageView
android:id="#+id/imgViewframeId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/photo_frame" />
</RelativeLayout>
Use one Parent layout and Use below XML code instead of your code, it will solve your problem.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/LevLayId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="140dp" >
<TextView
android:id="#+id/totlScorId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#drawable/score_timer"
android:gravity="center"
android:textColor="#ffffff" />
<TextView
android:id="#+id/levelId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/score_timer"
android:gravity="center"
android:textColor="#ffffff" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/LayAboButId"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/option_last_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="7px"
android:orientation="horizontal" >
<Button
android:id="#+id/opt3Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/option_normal_new"
android:gravity="center|center_vertical"
android:textColor="#ffffff"
android:textSize="11dp" />
<Button
android:id="#+id/opt4Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/option_normal"
android:gravity="center|center_vertical"
android:textColor="#ffffff"
android:textSize="11dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/option_pre_row"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/option_last_row"
android:layout_marginBottom="3px"
android:orientation="horizontal" >
<Button
android:id="#+id/opt1Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/option_normal_new"
android:gravity="center|center_vertical"
android:textColor="#ffffff"
android:textSize="11dp" />
<Button
android:id="#+id/opt2Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/option_normal"
android:gravity="center|center_vertical"
android:textColor="#ffffff"
android:textSize="11dp" />
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/imgLayId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:layout_marginRight="#id/totlScorId"
android:layout_marginTop="70dp" >
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<ImageView
android:id="#+id/imgViewId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<ImageView
android:id="#+id/imgViewframeId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="#drawable/photo_frame" />
</RelativeLayout>
</RelativeLayout>
Just started getting this today, so spotted the change which led to it.
In my case, it was because I've had to create a new layout directory layout-xhdpi for a new device.
Now, the new device thinks it's "large" (ie. it was using the layouts in layout-large); but it's really xhdpi.
So in the new layout xml, file I added reference to a value from a values-large/dimens.xml
However, this doesn't work.
Creating values-xhdpi/dimens.xml with the referenced value in it, solved the problem.
TL;DR make sure that you have a values-XXXXX directories for each layout-XXXXX directory, and that all relevant values are in there. I believe that values applicable to all sizes will be found in values/dimens.xml, but that's not how my app is structured, so I can't prove it.

Categories

Resources