tags:

views:

108

answers:

4

I am just starting out on android development and trying out the HelloAndroid tutorial. I have been stuck for a few days now. Initially, the first time I tried it, everything works perfectly and then I move on the second tutorial everything broke. So I'm trying to go back to the easiest and original tutorial and figure out what is happening.

There are three main file that I edited: HelloAndroid2.java package com.example.HelloAndroid2;

import android.app.Activity;
import android.os.Bundle;

public class HelloAndroid2 extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/textview"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:text="@string/hello"/>

strings.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, HelloAndroid2!</string>
    <string name="app_name">HelloAndroid2</string>
</resources>

These are all from the tutorial.

When I run it, the console output is:
[2010-07-06 16:37:16 - HelloAndroid2] ------------------------------
[2010-07-06 16:37:16 - HelloAndroid2] Android Launch!
[2010-07-06 16:37:16 - HelloAndroid2] adb is running normally.
[2010-07-06 16:37:16 - HelloAndroid2] Performing com.example.HelloAndroid2.HelloAndroid2 activity launch
[2010-07-06 16:37:16 - HelloAndroid2] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'HelloWorld'
[2010-07-06 16:37:16 - HelloAndroid2] WARNING: Application does not specify an API level requirement!
[2010-07-06 16:37:16 - HelloAndroid2] Device API version is 8 (Android 2.2)
[2010-07-06 16:37:16 - HelloAndroid2] Uploading HelloAndroid2.apk onto device 'emulator-5554'
[2010-07-06 16:37:16 - HelloAndroid2] Installing HelloAndroid2.apk...
[2010-07-06 16:37:22 - HelloAndroid2] Success!
[2010-07-06 16:37:22 - HelloAndroid2] Starting activity com.example.HelloAndroid2.HelloAndroid2 on device 
[2010-07-06 16:37:26 - HelloAndroid2] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.HelloAndroid2/.HelloAndroid2 }

So, it just gets stuck at the starting: intent... The emulator shows up with the time, date, and the fac that it is charging. I'm developing on Android 2.2. I try to get some data out of LogCat and these are the last few lines:

07-06 20:37:25.935: INFO/AndroidRuntime(387): NOTE: attach of thread 'Binder Thread #3' failed
07-06 20:37:27.265: INFO/ActivityManager(65): Displayed activity com.example.HelloAndroid2/.HelloAndroid2: 1461 ms (total 1461 ms)
07-06 20:37:32.376: DEBUG/dalvikvm(114): GC_EXPLICIT freed 562 objects / 31672 bytes in 95ms
07-06 20:37:37.386: DEBUG/dalvikvm(197): GC_EXPLICIT freed 82 objects / 7592 bytes in 87ms
07-06 20:37:42.386: DEBUG/dalvikvm(250): GC_EXPLICIT freed 26 objects / 1120 bytes in 102ms
07-06 20:38:10.437: DEBUG/SntpClient(65): request time failed: java.net.SocketException: Address family not supported by protocol

So basically, nothing happen on the emulator and it should say HelloAndroid or something like that. Please help.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.HelloAndroid2"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloAndroid2"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>


</manifest> 
A: 
WARNING: Application does not specify an API level requirement!

define android:minSdkVersion inside your manifest.xml file

   </application>

  <uses-sdk android:minSdkVersion="3" />

</manifest> 
Jorgesys
Thanks Jorgesys! I tried but it still does not work. On the console output, I'm still stuck at:[2010-07-07 13:40:00 - HelloAndroid2] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.HelloAndroid2/.HelloAndroid2 }and the emulator is showing the same screen and not HelloAndroid text.
Yko
A: 

So why not start out simple, and create a new AVD while specifying a min. SDK for it, so it'll be there.

Then to run that AVD reliably enough, make sure no Android apps are running, then from Eclipse Run!Run Configurations...!Target!Manual!<Run>!Launch a new Android Virtual Device![then click onto the pane's line item to highlight that AVD]!<OK>.

Wait for the thing to load (wait for the "ActivityManager: Starting: Intent" line on your Eclipse Console feedback). Then press <Menu> on the skin.

If that AVD is already running and you want to run it again, change a line in your Java code, then Run!Run Configurations...!Target!Automatic!<Apply>!<Run>.

Thank you user225626! I tried this and it works! However, there are some glitches.After I create a new AVD and run it as target->manual-> new AVD, I can get the emulator to display the simple HelloAndroid string. So that works; however, when I go back to run-> run configurations -> target -> automatic, the only AVD listed for deployment is the original (old and broken) one instead of the new one. When I try with that one, it doesn't work. Worst, once I use the old one, even if I choose manual and select the new one, the new one now stops working.
Yko
In other words, I have to create a new AVD. From there, I can click run -> run and it will ask for the current AVD running (new one) and any changes I made will show up at the emulator. So it adds one more step at least it works :)
Yko
Additional info on the AVD error:When I try the old AVD (Android 2.2; the new one is Android 2.1u1), the emulator starts from black screen with android then to a blue background with a lock symbol on the left and a sound/volume symbol on the right. It also have the time, date, and charging in the middle. However, with the other AVD, it goes from black screen to a display with google search with blue background and icons. Then, it shows the correct output. It just seems strange. Thanks for the help. In the meantime I will just delete the 2.2 AVD and stick with the new 2.1 AVD. Thanks a lot!
Yko
A: 

@user225626 Thank you for the advice. I did what you advised step by step. Same problem. And it seems I can't ignore this problem, because I encounter same problem when trying second tutorial 'Hello, view'....

This is the hardest 'Hello, world' program I ever wrote. :)

Regards, Hsieh

Following are what I tried and got.

  1. create a new virtual device with platform 2.1 update1.
  2. create a new project 'HelloAndroid21', set minSDK to 7.
  3. modify .java file as tutorial suggested (hard-coded to show "Hello, Android" in onCreate)
  4. The first run, "Hello, Android" showed.
  5. Second run, my com.example.helloandroid21 package uploaded successfully, but "Hello, Android" did not show. Only the home layout of emulator showed.
  6. Do project-clean...
  7. Run again. "Hello, Android" still not showed.
  8. Following are logs.
  9. I tried second tutorial 'Hello, View', failed to show the right output, only home page of emulator is showed.... :(

------When create new project---------

In Error Log view, showed "fail to load properties file for project 'HelloAndroid21'".

I don't know how to solve this problem, so I ignored it.


Then, got right output when run the application at the first time.

When run 2nd or 3rd time:

----------In console view, showed:---------------- [2010-07-07 20:33:30 - HelloAndroid21] ------------------------------

[2010-07-07 20:33:30 - HelloAndroid21] Android Launch!

[2010-07-07 20:33:30 - HelloAndroid21] adb is running normally.

[2010-07-07 20:33:30 - HelloAndroid21] Performing com.example.helloandroid21.HelloAndroid21 activity launch

[2010-07-07 20:33:44 - HelloAndroid21] Launching a new emulator with Virtual Device 'adv21-0'

[2010-07-07 20:33:48 - HelloAndroid21] New emulator found: emulator-5554

[2010-07-07 20:33:48 - HelloAndroid21] Waiting for HOME ('android.process.acore') to be launched...

[2010-07-07 20:34:36 - HelloAndroid21] HOME is up on device 'emulator-5554'

[2010-07-07 20:34:36 - HelloAndroid21] Uploading HelloAndroid21.apk onto device 'emulator-5554'

[2010-07-07 20:34:36 - HelloAndroid21] Installing HelloAndroid21.apk...

[2010-07-07 20:35:03 - HelloAndroid21] Success!

[2010-07-07 20:35:03 - HelloAndroid21] Starting activity com.example.helloandroid21.HelloAndroid21 on device

[2010-07-07 20:35:18 - HelloAndroid21] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.example.helloandroid21/.HelloAndroid21 }


wj.hsieh
Are you changing any Java code between 4.The first run, "Hello, Android" showed., and 5.Second run, my com.example.helloandroid21 package uploaded successfully, but "Hello, Android" did not show. Only the home layout of emulator showed.? This is your more complex HelloAndroid tutorial?
And does your simple HelloAndroid example run reliably no matter how many times you reload it during the AVD runtime?
check the user225626 response...
Jorgesys
I did the 'run configuration' as you advised, plus had 'wipe user data' checked. Then, all of my HelloAndroid projects worked with any of my virtual devices, even the second tutorial 'Hello, View' worked, too. Thank you for pointing out where the problem is. Thank you very very very much. :)Regards,Hsieh
wj.hsieh
A: 

Btw, in LogCat view, there are many messages displayed. One of them is 'fail to attach thread', then the VM is shut down. It looks this happened after HOME is on and prior/next to ActivityManager trying to do HelloAndroid21Activity.

wj.hsieh
So can you post your source code? (And what about my other question: Does your simpler HelloAndroid reload all the time no prob?)