1. Download our Official Android App: Forums for Android!

Apps main.xml layout help

Discussion in 'Android Development' started by davidsimon, Jun 12, 2011.

  1. davidsimon

    davidsimon Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    Dec 16, 2009

    Dec 16, 2009
    20
    3
    16
    Hi all,

    I'm new to android development. I have some experience with Java but nothing when it comes to xml. I'm making the second application the book I'm using is instructing which is a silent mode toggle. However, I can't get my main layout working properly.
    Code (Text):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.               android:layout_width="fill_parent"
    4.               android:layout_height="fill_parent"
    5.               android:orientation="vertical" >
    6.              
    7.     <ImageView
    8.         android:id="@+id/phone_icon"
    9.         android:layout_width=
     

    Attached Files:


    Advertisement

    Maleeha Ali likes this.
  2. GIR

    GIR Well-Known Member
    Rank:
    None
    Points:
    18
    Posts:
    96
    Joined:
    Feb 14, 2010

    Feb 14, 2010
    96
    10
    18
    Classified.
    UK
    Sometime, just sometimes, the SDK throws a wobbly and needs restarting, as It's the only way I've found to solve this issue when I've encountered it myself.

    Another problem can occur when code is copyed and paste from another program like gedit, open office, etc, and found that cuuting ALL the code out and manualy re-entering it works because it removes any errant line feeds, carriage returns or other no-printing characters.

    What do you mean when you mention the setup of your png's? which directory have you placed them in? have you been editing the png's in a program and saved as a png without being converted to the png format?

    Hope this helps.
    GIR
     
    Maleeha Ali and davidsimon like this.
  3. davidsimon

    davidsimon Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    Dec 16, 2009

    Dec 16, 2009
    20
    3
    16
    How do I restart the SDK?

    I manually enterred all the code myself the first time and tried playing around or copying and pasting other code for about an hour trying to get this to stop throwing the error with no luck.

    I was thinking just the setup of all the images I was using might not have been done right since I took a shortcut not wanting to make different sized images for each resolution since this is only my second android app ever and I won't really be using it other than for learning purposes. I took all my pngs from the web that fell under the requirements the book listed. I have one for the icon, and two for images to show depending on the current mode of the phone (on or silent). These were place in the drawable folders but I used the same three images in ldpi, mdpi and hdpi.

    Thanks for the help!
     
  4. miXer

    miXer Android Enthusiast
    Rank:
    None
    Points:
    53
    Posts:
    313
    Joined:
    Aug 12, 2010

    Aug 12, 2010
    313
    51
    53
    Norway
    Restart Eclipse

    You have forgot a + at the button id.
     
    Maleeha Ali and davidsimon like this.
  5. davidsimon

    davidsimon Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    Dec 16, 2009

    Dec 16, 2009
    20
    3
    16
    This is my third day trying to get this working, I've closed and reopenned Eclipse many times :( I added the '+' in android:id=
     
    Maleeha Ali likes this.
  6. GIR

    GIR Well-Known Member
    Rank:
    None
    Points:
    18
    Posts:
    96
    Joined:
    Feb 14, 2010

    Feb 14, 2010
    96
    10
    18
    Classified.
    UK
    Glad to be of help, don't forget there is a 'thanks' button :)

    I have found your problem, the quotes used after the line
    Code (Text):
    1. <ImageView
    2.         android:id="@+id/phone_icon"
    are in a different encoding. :D

    To fix simple delete ALL you quote marks and manually re-enter them.

    I only found the problem after copying your xml file into eclipse and seeing for myself.

    Code after replacement =
    Code (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.               android:layout_width="fill_parent"
    5.               android:layout_height="fill_parent"
    6.               android:orientation="vertical" >
    7.              
    8.     <ImageView
    9.         android:id="@+id/phone_icon"
    10.         android:layout_width="wrap_content"
    11.         android:layout_height="wrap_content"
    12.         android:layout_gravity="center_horizontal"
    13.         android:src="@drawable/phone_on" />
    14.    
    15.     <Button
    16.         android:id="@id/toggleButton"
    17.         android:layout_width="wrap_content"
    18.         android:layout_height="wrap_content"
    19.         android:layout_gravity="center_horizontal"
    20.         android:text="Toggle Silent Mode"
    21.         />
    22.        
    23. </LinearLayout>
    24.  
    Simply copy and paste this into your xml file and all will be well.

    It has to be said that this is one danger of copying code from websites - when you copy them your pc also grabs the encoding info along with it (as described in whatever sites html files) - and when its pasted back into eclipse the encoding is also embedded .

    Hop ethis helps,
    GIR
     
    Maleeha Ali and davidsimon like this.
  7. davidsimon

    davidsimon Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    20
    Joined:
    Dec 16, 2009

    Dec 16, 2009
    20
    3
    16
    How did you figure this out? Is there a way to see the encoding in Eclipse? What does that really mean, different encoding?

    So helpful, thanks so much. You have no idea how close I was to giving up. What's strange is that I thought I wrote most of the code manually. All that time trying to play around with it must have gotten to my head. The book I'm using is a pdf so I assume the same thing about the encoding applies there too. I'll make sure to be extra careful when copying text in the future.
     
    Maleeha Ali likes this.
  8. GIR

    GIR Well-Known Member
    Rank:
    None
    Points:
    18
    Posts:
    96
    Joined:
    Feb 14, 2010

    Feb 14, 2010
    96
    10
    18
    Classified.
    UK
    Maleeha Ali likes this.
  9. Maleeha Ali

    Maleeha Ali Lurker
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Dec 13, 2013

    Dec 13, 2013
    1
    0
    5
    Female
    Thank you SO much DavidSimon for discussing this problem over here. I myself was facing the exact same problem in Eclipse. I am pretty sure you are reading the same "PDF book" that I am using to learn Android Development :D and I did the same thing : copying and pasting the code to eclipse. My app works now!

    And Thanks to you GIR for finding the solution for these errors. Because of you I am able to continue programming. Really, thanks a lot!
     

Share This Page

Loading...