为什么我的 android 应用程序在模拟器中 运行 时停止了?

Why my android application stopped when I run it in Emulator?

Unfortunately, app has stopped.

当我在模拟器中 运行 我的应用程序时出现此错误。为什么? 我的程序不包含任何错误,但它不是 运行.

我使用带 SDK 的 Eclipse。

这是我的清单文件:

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

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

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

06-09 07:30:20.989: D/AndroidRuntime(627): Shutting down VM
06-09 07:30:20.989: W/dalvikvm(627): threadid=1: thread exiting with uncaught exception (group=0x40a122a0)
06-09 07:30:21.049: E/AndroidRuntime(627): FATAL EXCEPTION: main
06-09 07:30:21.049: E/AndroidRuntime(627): java.lang.RuntimeException: Unable to resume activity {com.example.jvstgs/com.example.jvstgs.Tetris}: java.lang.SecurityException: Neither user 10044 nor current process has android.permission.WAKE_LOCK
06-09 07:30:21.049: E/AndroidRuntime(627): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2575)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2603)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2089)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.app.ActivityThread.access0(ActivityThread.java:130)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.os.Handler.dispatchMessage(Handler.java:99)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.os.Looper.loop(Looper.java:137)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.app.ActivityThread.main(ActivityThread.java:4745)
06-09 07:30:21.049: E/AndroidRuntime(627): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 07:30:21.049: E/AndroidRuntime(627): at java.lang.reflect.Method.invoke(Method.java:511)
06-09 07:30:21.049: E/AndroidRuntime(627): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
06-09 07:30:21.049: E/AndroidRuntime(627): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-09 07:30:21.049: E/AndroidRuntime(627): at dalvik.system.NativeStart.main(Native Method)
06-09 07:30:21.049: E/AndroidRuntime(627): Caused by: java.lang.SecurityException: Neither user 10044 nor current process has android.permission.WAKE_LOCK.
06-09 07:30:21.049: E/AndroidRuntime(627): at android.os.Parcel.readException(Parcel.java:1425)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.os.Parcel.readException(Parcel.java:1379)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.os.IPowerManager$Stub$Proxy.acquireWakeLock(IPowerManager.java:288)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.os.PowerManager$WakeLock.acquireLocked(PowerManager.java:309)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.os.PowerManager$WakeLock.acquire(PowerManager.java:288)
06-09 07:30:21.049: E/AndroidRuntime(627): at com.example.framework.impl.GLGame.onResume(GLGame.java:66)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1184)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.app.Activity.performResume(Activity.java:5082)
06-09 07:30:21.049: E/AndroidRuntime(627): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2565)
06-09 07:30:21.049: E/AndroidRuntime(627): ... 12 more

如果您阅读日志,您会看到:

java.lang.SecurityException: Neither user 10044 nor current process has android.permission.WAKE_LOCK

这意味着您需要将 android.permission.WAKE_LOCK 添加到您的 AndroidManifest.xml

请阅读:https://developer.android.com/training/scheduling/wakelock.html

To use a wake lock, the first step is to add the WAKE_LOCK permission to your application's manifest file:

尝试将 WAKE_LOCK_PERMISSION 添加到您的清单 uses-permission

更多信息在这里:http://developer.android.com/reference/android/Manifest.permission.html#WAKE_LOCK

看来问题出在您的权限上:

java.lang.SecurityException: Neither user 10044 nor current process has android.permission.WAKE_LOCK

更新您的清单以包含此行:

<uses-permission android:name="android.permission.WAKE_LOCK" />

你的堆栈跟踪

顺便说一句,每个人之所以能够如此迅速地找出您的问题,是因为您的 logcat 清楚地表明了您的错误所在。

阅读 this post 以了解有关如何读取堆栈跟踪的更多信息。