如何使用AVD正确运行Android应用程序?

时间:2014-02-11 12:28:43

标签: java android

我正在尝试运行我的第一个Android应用程序。 我在developer.android.com上按照教程“我的第一个应用程序”。

activity_main.xml很简单:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <EditText
        android:id="@+id/edit_message"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:hint="@string/edit_message" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="@string/send_button" />

</LinearLayout>

MainActivity.java是默认值。

问题在于,当我运行我的Andoid应用程序时,它确实打开了新的虚拟设备,但是黑屏和右侧窗格上有几个按钮。所以我的activity_main.xml没有显示任何内容。

在控制台中我看到了这样的输出:

[2014-02-11 14:21:20 - MyFirstApp] ------------------------------
[2014-02-11 14:21:20 - MyFirstApp] Android Launch!
[2014-02-11 14:21:20 - MyFirstApp] adb is running normally.
[2014-02-11 14:21:20 - MyFirstApp] Performing com.example.myfirstapp.MainActivity activity launch
[2014-02-11 14:21:20 - MyFirstApp] Automatic Target Mode: Unable to detect device compatibility. Please select a target device.
[2014-02-11 14:21:34 - MyFirstApp] Launching a new emulator with Virtual Device 'MyVirtualDevice'
[2014-02-11 14:22:17 - MyFirstApp] emulator-5554 disconnected! Cancelling 'com.example.myfirstapp.MainActivity activity launch'!
[2014-02-11 14:22:54 - Emulator] Failed to create Context 0x3005
[2014-02-11 14:22:54 - Emulator] emulator: WARNING: Could not initialize OpenglES emulation, using software renderer.
[2014-02-11 14:22:54 - Emulator] WARNING: Data partition already in use. Changes will not persist!
[2014-02-11 14:22:54 - Emulator] WARNING: SD Card image already in use: C:\Users\Vova\.android\avd\MyVirtualDevice.avd/sdcard.img
[2014-02-11 14:22:54 - Emulator] WARNING: Cache partition already in use. Changes will not persist!
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:54 - Emulator] could not get wglGetExtensionsStringARB
[2014-02-11 14:22:55 - Emulator] emulator: warning: opening audio input failed
[2014-02-11 14:22:55 - Emulator] 
[2014-02-11 14:22:56 - MyFirstApp] New emulator found: emulator-5556
[2014-02-11 14:22:56 - MyFirstApp] Waiting for HOME ('android.process.acore') to be launched...
[2014-02-11 14:23:08 - MyFirstApp] emulator-5556 disconnected! Cancelling 'com.example.myfirstapp.MainActivity activity launch'!

我的AndroidManifest.xml是:

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.myfirstapp.MainActivity"
            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>

有什么不对?

谢谢!

3 个答案:

答案 0 :(得分:1)

欢迎来到Android开发世界。 这里有一些事情:

  1. 当使用该图像的人已经在运行时,模拟器抱怨您正在尝试启动新的模拟器。启动时选择现有(正在运行)的模拟器。
  2. 检查以确保您在模拟器上运行的API级别与清单中的级别相匹配(级别18)
  3. 我强烈建议使用Genymotion - 这是一个(更多!!)更快的模拟器

答案 1 :(得分:0)

这似乎是您的IDE的问题,而不是您的代码。控制台经常声明设备已断开连接,因此取消了您的程序 如果我们知道你正在使用什么IDE,它会有所帮助.Android Studio,Eclipse或其他? 那么有人可能会给你更具体的建议如何解决AVD的问题,如果你自己无法弄明白的话。 ;)

答案 2 :(得分:0)

你有api 18的sdk吗?。因为你已经在你的manifest.try中设置了这个,以便将目标版本设置为你安装的那个。