• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps main.xml layout help

davidsimon

Newbie
Dec 16, 2009
20
3
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:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent" 
              android:orientation="vertical" >
              
	<ImageView 
		android:id="@+id/phone_icon"
		android:layout_width=
 

Attachments

  • MainActivityError.jpg
    MainActivityError.jpg
    51.5 KB · Views: 53
  • MainXMLerror.jpg
    MainXMLerror.jpg
    194.3 KB · Views: 48
  • Like
Reactions: Maleeha Ali
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
 
Upvote 0
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.
How do I restart the SDK?

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.
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.

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?
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!
 
Upvote 0
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:
<ImageView 
        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:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent" 
              android:layout_height="fill_parent" 
              android:orientation="vertical" >
              
    <ImageView 
        android:id="@+id/phone_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/phone_on" />
    
    <Button 
        android:id="@id/toggleButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:text="Toggle Silent Mode"
        />
        
</LinearLayout>

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
 
Upvote 0
I have found your problem, the quotes used after the line
Code:
<ImageView 
        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.
How did you figure this out? Is there a way to see the encoding in Eclipse? What does that really mean, different encoding?

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

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.
 
  • Like
Reactions: Maleeha Ali
Upvote 0
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!
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones