无法在模拟器上运行 Android 应用程序

Not able to run Android App on Emulator

我正在学习 android 应用程序开发作为初学者。该应用程序未在模拟器上运行。错误说:

Unfortunately,Appname has stopped.

我已经完成了这里解决的类似主题,但我仍然找不到问题所在。从 logcat 日志来看,似乎存在超时问题,但是通过 eclipse -> window -> preferences -> Android -> DDMS 将超时值增加到 50 秒,它仍然显示相同的 错误 。 有帮助吗?

MainActivity.java

package com.example.myfirstapp;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;


public class MainActivity extends ActionBarActivity implements OnClickListener{

private Button theButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    theButton = (Button)findViewById(R.id.myButton);
    theButton.setOnClickListener(this);
}

public void onClick(View v){
    if(v.getId()==theButton.getId()){
         theButton.setText("Ouch");
     }
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
 }
}

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="20" />

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

Logcat

01-02 11:39:23.260: W/WearableConn(485): Error writing to device, error: failed to     connect to /10.0.2.2 (port 5601): connect failed: ETIMEDOUT (Connection timed out)
01-02 11:39:23.310: I/WearableConn(485): Socket closed
01-02 11:39:23.360: I/WearableConn(485): Waiting 2.0 seconds to retry connection
01-02 11:39:25.400: I/WearableConn(485): Connecting via TCP to /10.0.2.2:5601
01-02 11:39:25.480: D/dalvikvm(455): GC_EXPLICIT freed 888K, 30% free 3283K/4632K, paused 4ms+5ms, total 48ms
01-02 11:39:33.190: I/Choreographer(455): Skipped 36 frames!  The application may be doing too much work on its main thread.
01-02 11:39:33.220: I/ActivityManager(354): START u0 {act=android.intent.action.MAIN flg=0x10000000 cmp=com.example.myfirstapp/.MainActivity} from pid 455 on display 0
01-02 11:39:33.260: D/LightsService(354): Excessive delay setting light: 63ms
01-02 11:39:33.410: D/gralloc(49): Registering a buffer in the process that created it. This may cause memory ordering problems.
01-02 11:39:33.410: E/libEGL(49): called unimplemented OpenGL ES API
01-02 11:39:33.420: E/libEGL(49): called unimplemented OpenGL ES API
01-02 11:39:33.420: W/WindowManager(354): Screenshot failure taking screenshot for (123x221) to layer 21000
01-02 11:39:33.420: E/libEGL(49): called unimplemented OpenGL ES API
01-02 11:39:33.420: E/libEGL(49): called unimplemented OpenGL ES API
01-02 11:39:33.420: E/SurfaceFlinger(49): glCheckFramebufferStatusOES error -1331883460
01-02 11:39:33.420: E/SurfaceFlinger(49): got GL_FRAMEBUFFER_COMPLETE_OES error while taking screenshot
01-02 11:39:33.420: E/libEGL(49): called unimplemented OpenGL ES API
01-02 11:39:33.420: E/libEGL(49): called unimplemented OpenGL ES API
01-02 11:39:33.460: I/Choreographer(354): Skipped 46 frames!  The application may be doing too much work on its main thread.
01-02 11:39:33.590: D/LightsService(354): Excessive delay setting light: 61ms
01-02 11:39:33.620: I/ActivityManager(354): Start proc com.example.myfirstapp for activity com.example.myfirstapp/.MainActivity: pid=745 uid=10018 gids={50018}
01-02 11:39:33.640: D/dalvikvm(745): Not late-enabling CheckJNI (already on)
01-02 11:39:33.670: E/HostWithRpcCallback(455): Failed to send RPC
01-02 11:39:33.670: E/HostWithRpcCallback(455): com.google.android.wearable.gmsclient.WearableException: sendRpcAsync failed: Status{statusCode=unknown status code: 4000, resolution=null}
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at com.google.android.wearable.gmsclient.GoogleApiClientHelper.throwIfFailed(GoogleApiClientHelper.java:98)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at com.google.android.wearable.gmsclient.MessageManager.getResult(MessageManager.java:81)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at com.google.android.wearable.gmsclient.MessageManager.getResult(MessageManager.java:78)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at com.google.android.clockwork.actions.WearableHostWithRpcCallback$SendRpcCallbackWithId.onSendRpc(WearableHostWithRpcCallback.java:292)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at com.google.android.wearable.gmsclient.MessageManager.onResult(MessageManager.java:78)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at com.google.android.wearable.gmsclient.MessageManager.onResult(MessageManager.java:75)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at com.google.android.gms.common.api.BaseImplementation$CallbackHandler.deliverResultCallback(Unknown Source)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at com.google.android.gms.common.api.BaseImplementation$CallbackHandler.handleMessage(Unknown Source)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at android.os.Handler.dispatchMessage(Handler.java:102)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at android.os.Looper.loop(Looper.java:136)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at android.app.ActivityThread.main(ActivityThread.java:5026)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at java.lang.reflect.Method.invokeNative(Native Method)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at java.lang.reflect.Method.invoke(Method.java:515)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
01-02 11:39:33.670: E/HostWithRpcCallback(455):     at dalvik.system.NativeStart.main(Native Method)
01-02 11:39:34.030: D/AndroidRuntime(745): Shutting down VM
01-02 11:39:34.030: W/dalvikvm(745): threadid=1: thread exiting with uncaught exception (group=0xb4a22d70)
01-02 11:39:34.040: E/AndroidRuntime(745): FATAL EXCEPTION: main
01-02 11:39:34.040: E/AndroidRuntime(745): Process: com.example.myfirstapp, PID: 745
01-02 11:39:34.040: E/AndroidRuntime(745): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.app.ActivityThread.access0(ActivityThread.java:138)
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.os.Handler.dispatchMessage(Handler.java:102)
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.os.Looper.loop(Looper.java:136)
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.app.ActivityThread.main(ActivityThread.java:5026)
01-02 11:39:34.040: E/AndroidRuntime(745):  at java.lang.reflect.Method.invokeNative(Native Method)
01-02 11:39:34.040: E/AndroidRuntime(745):  at java.lang.reflect.Method.invoke(Method.java:515)
01-02 11:39:34.040: E/AndroidRuntime(745):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
01-02 11:39:34.040: E/AndroidRuntime(745):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
01-02 11:39:34.040: E/AndroidRuntime(745):  at dalvik.system.NativeStart.main(Native Method)
01-02 11:39:34.040: E/AndroidRuntime(745): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
01-02 11:39:34.040: E/AndroidRuntime(745):  at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:277)
01-02 11:39:34.040: E/AndroidRuntime(745):  at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2889)
01-02 11:39:34.040: E/AndroidRuntime(745):  at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3154)
01-02 11:39:34.040: E/AndroidRuntime(745):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:305)
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.app.Activity.setContentView(Activity.java:1930)
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:217)
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:77)
01-02 11:39:34.040: E/AndroidRuntime(745):  at com.example.myfirstapp.MainActivity.onCreate(MainActivity.java:18)
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.app.Activity.performCreate(Activity.java:5242)
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
01-02 11:39:34.040: E/AndroidRuntime(745):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
01-02 11:39:34.040: E/AndroidRuntime(745):  ... 11 more
01-02 11:39:34.100: W/ActivityManager(354):   Force finishing activity com.example.myfirstapp/.MainActivity
01-02 11:39:34.120: W/InputMethodManagerService(354): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@b4ebb730 attribute=null, token = android.os.BinderProxy@b4e0fa08
01-02 11:39:34.350: I/Choreographer(354): Skipped 95 frames!  The application may be doing too much work on its main thread.
01-02 11:39:34.470: I/Choreographer(354): Skipped 32 frames!  The application may be doing too much work on its main thread.
01-02 11:39:34.570: I/Choreographer(354): Skipped 34 frames!  The application may be doing too much work on its main thread.
01-02 11:39:34.620: I/Choreographer(354): Skipped 35 frames!  The application may be doing too much work on its main thread.
01-02 11:39:34.630: W/ActivityManager(354): Activity pause timeout for ActivityRecord{b4eb1738 u0 com.example.myfirstapp/.MainActivity t4 f}
01-02 11:39:34.690: I/Choreographer(354): Skipped 56 frames!  The application may be doing too much work on its main thread.
01-02 11:39:34.730: I/Choreographer(354): Skipped 34 frames!  The application may be doing too much work on its main thread.
01-02 11:39:34.830: E/HostWithRpcCallback(455): Failed to send RPC
01-02 11:39:34.830: E/HostWithRpcCallback(455): com.google.android.wearable.gmsclient.WearableException: sendRpcAsync failed: Status{statusCode=unknown status code: 4000, resolution=null}
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at com.google.android.wearable.gmsclient.GoogleApiClientHelper.throwIfFailed(GoogleApiClientHelper.java:98)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at com.google.android.wearable.gmsclient.MessageManager.getResult(MessageManager.java:81)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at com.google.android.wearable.gmsclient.MessageManager.getResult(MessageManager.java:78)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at com.google.android.clockwork.actions.WearableHostWithRpcCallback$SendRpcCallbackWithId.onSendRpc(WearableHostWithRpcCallback.java:292)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at com.google.android.wearable.gmsclient.MessageManager.onResult(MessageManager.java:78)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at com.google.android.wearable.gmsclient.MessageManager.onResult(MessageManager.java:75)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at com.google.android.gms.common.api.BaseImplementation$CallbackHandler.deliverResultCallback(Unknown Source)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at com.google.android.gms.common.api.BaseImplementation$CallbackHandler.handleMessage(Unknown Source)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at android.os.Handler.dispatchMessage(Handler.java:102)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at android.os.Looper.loop(Looper.java:136)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at android.app.ActivityThread.main(ActivityThread.java:5026)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at java.lang.reflect.Method.invokeNative(Native Method)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at java.lang.reflect.Method.invoke(Method.java:515)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
01-02 11:39:34.830: E/HostWithRpcCallback(455):     at dalvik.system.NativeStart.main(Native Method)
01-02 11:39:35.640: I/Process(745): Sending signal. PID: 745 SIG: 9
01-02 11:39:35.660: I/ActivityManager(354): Process com.example.myfirstapp (pid 745) has died.
01-02 11:39:35.750: W/InputMethodManagerService(354): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@b4f00610 attribute=null, token = android.os.BinderProxy@b4e0fa08
01-02 11:39:35.800: I/Choreographer(354): Skipped 166 frames!  The application may be doing too much work on its main thread.
01-02 11:39:35.880: D/dalvikvm(354): GC_FOR_ALLOC freed 502K, 13% free 4406K/5048K, paused 63ms, total 69ms
01-02 11:39:35.890: I/Choreographer(354): Skipped 40 frames!  The application may be doing too much work on its main thread.

您的错误日志清楚地说明了由以下原因引起的错误:

Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.

4.4W 是 AndroidWear SDK。只是不要 Android 磨损 SDK 并在 Androidmanifest.xml 文件中将目标 sdk 版本更改为 19,如此处所示

在清单标签内,如果不存在则添加此标签

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

不要使用 API 级别 20 作为 Android 虚拟设备。请改用 API 级别 19 和平台 4.4.2。

我遇到了这个问题并通过以下方式解决了: Open the android SDK manager and remove Android wear sdk and its package completely and try to run you android application.