Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My Android "Hello World" app doesn't say "Hello"

Tags:

android

I created a Hello World application, and the system generated most of the Android language below. When running the app without the System.out statement, there is no "Hello" displayed in the emulator. Then, using the Eclipse tutorial, I read that I can add the System.out.println statement to main. Again the app runs, but there is no output.

What am I not understanding here?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    System.out.println =" Hello world!" 
    />
</LinearLayout>
like image 651
keith Avatar asked Apr 02 '10 00:04

keith


2 Answers

I had this same problem, turns out all I had to do was be more patient.

The initial load time of the AVD seems like FOREVER... and in Eclipse before it actually looks like the device is booting up it just says "ANDROID_" against a fully black screen for quite a while. I thought it wasn't loading my text "Hello, Android" correctly, but it was actually just a load screen and I didn't wait long enough. (Yes, I now feel like a moron and a noob.)

If you're following along with the Android Developers Hello World Tutorial, and it doesn't seem like it's working, if you've never loaded the AVD before... maybe just wait longer?

like image 56
fairyrebel Avatar answered Nov 11 '22 05:11

fairyrebel


Beginners' questions are fine, but boy, this really is a beginner question :) As for your problem, it can be a few things. What's probably happened is that you've adapted the basic "Hello, Android" tutorial which defines the TextViews in code, to make it display using an XML file. However, when you did that, you didn't change the code to use that XML file, and instead it's trying to display your old TextView. Also, "System.out.println="hello world!" won't do anything when in your XML file - you need to put statements like that in the code itself. In fact, offhand I can't remember if System.out.... even does anything in Android - debugging lines should be issued using Log.d("some title", "your message"), as that outputs to the Android specific logging device.

Anyway, it'd be easier to help solve your problem if you showed a bit more of your code. Try to make sure it's formatted properly, e.g. indenting code lines by four spaces. You can preview your post before you submit your edited version in the lower window to make sure it looks right.

like image 2
Steve Haley Avatar answered Nov 11 '22 06:11

Steve Haley