Android app not launching on emulator

2019-02-14 15:56发布

问题:

I'm testing a simple hello app and it's not launching on the emulator. There's no errors and the console is this:

[2010-11-16 21:26:06 - Hello World] ------------------------------  
[2010-11-16 21:26:06 - Hello World] Android Launch!  
[2010-11-16 21:26:06 - Hello World] adb is running normally.  
[2010-11-16 21:26:06 - Hello World] Performing com.hello.HelloWorld.HelloWorld activity launch  
[2010-11-16 21:26:09 - Hello World] Launching a new emulator with Virtual Device 'VirtualDevice2.2'    

The emulator launches and the screen appears with the lock and my app doesn't start.
Tried to unlock and go to launcher to look for my app and it's not there.
Anyone can help me on this one?
Thanks.

Code:


package com.hello.HelloWorld;

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

public class HelloWorld extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        // We want to view some very simple text, so we need a TextView
        TextView tv = new TextView(this);
        // Put some text to the newly created TextVIew
        tv.setText("Hello Android");
        // Tell our App to display the textView
        this.setContentView(tv);
    }
}

Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      android:versionCode="1"
      android:versionName="1.0" package="com.hello.HelloWorld">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloWorld"
                  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>
    <uses-sdk android:minSdkVersion="8" />

</manifest> 

回答1:

I'm going to guess you're developing on Windows 7 or Vista. In either case, your hosts file maps "localhost" to "::1". Android (as of 2.2) doesn't handle IPv6 very well, so you'll find a "protocol bind" failure further up in your logs (not the logcat stuff, DDMS IIRC).

To fix this, you need to change the definition of localhost to "127.0.0.1". c:\windows\system32\drivers\etc\hosts. Change "::1" to "127.0.0.1". IIRC, you have to saveAs to a different name, delete the original, then rename back to "hosts", with no extension.


Or you could be using an HTC device without their home grown USB driver. Check out HTC's support pages for the "HTC Synch" app for your OS.