Android app not launching on emulator

2019-02-28 10:55发布

问题:

I just set up eclipse to start android development according to this http://developer.android.com/sdk/installing.html. My problem seems similar to this one: Android app not launching on emulator, but the solution will not work. I am trying to run a simple hello app. I do not get any errors but here is the console:

[2011-06-01 10:03:53 - HelloAndroid] ------------------------------
[2011-06-01 10:03:53 - HelloAndroid] Android Launch!
[2011-06-01 10:03:53 - HelloAndroid] adb is running normally.
[2011-06-01 10:03:53 - HelloAndroid] Performing com.example.helloandroid.HelloAndroid activity launch
[2011-06-01 10:04:00 - HelloAndroid] Launching a new emulator with Virtual Device 'AVD2.2'

Here is the little code that I have:

package com.example.helloandroid;

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

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       tv.setText("Hello, Android");
       setContentView(tv);
   }
}

Here is the manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.helloandroid"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".HelloAndroid"
                  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>

The emulator launches and goes to a screen where I can unlock it. The emulator seems to work but the app is never launched. Also when I have the emulator running and I go and try to relaunch the app by clicking run as... Android application and a pop up box asks me to choose an emulator to launch, the running emulator is not shown.

回答1:

Try adding

<category android:name="android.intent.category.DEFAULT" />

Eclipse by default launches the DEFAULT activity. If that does not work, right click on the project, and check the run configurations. You have an option to set which activity to launch.

Also, you should be able to see the icon for your app in the applications drawer on the emulator launcher. Click on that icon and see if the app launches. If it does not, then the problem is in your activity somehow (although I did not see anything wrong in it).

If those two do not work, try restarting adb from the command prompt:

>adb kill-server
>adb start-server


回答2:

Sometimes in the similar situation clearing the project helped...

Have you set the appname in the strings.xml file?