我不知道为什么会收到此错误,我花了大约两个小时来尝试查找源,但是我一直在转圈。您可以快速浏览一下,看看有什么问题吗?
WakeLock代码:-
wakeLock = powerManager.newWakeLock(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, "GLGame");
这是LogCat的输出:
11-02 22:07:19.114: D/SensorGUI(517): SensorChannel(const Parcel& data): mSendFd = -1, mReceiveFd = 55
11-02 22:07:19.114: D/SensorManager(517): [SensorManager] registerListener: delay = 20000
11-02 22:07:19.565: D/AndroidRuntime(517): Shutting down VM
11-02 22:07:19.565: W/dalvikvm(517): threadid=1: thread exiting with uncaught exception (group=0x40abf228)
11-02 22:07:19.615: E/AndroidRuntime(517): FATAL EXCEPTION: main
11-02 22:07:19.615: E/AndroidRuntime(517): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.an.chess/com.an.chess.ChessGame}: java.lang.IllegalArgumentException
11-02 22:07:19.615: E/AndroidRuntime(517): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2194)
11-02 22:07:19.615: E/AndroidRuntime(517): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
11-02 22:07:19.615: E/AndroidRuntime(517): at android.app.ActivityThread.access$600(ActivityThread.java:139)
11-02 22:07:19.615: E/AndroidRuntime(517): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
11-02 22:07:19.615: E/AndroidRuntime(517): at android.os.Handler.dispatchMessage(Handler.java:99)
11-02 22:07:19.615: E/AndroidRuntime(517): at android.os.Looper.loop(Looper.java:154)
11-02 22:07:19.615: E/AndroidRuntime(517): at android.app.ActivityThread.main(ActivityThread.java:4945)
11-02 22:07:19.615: E/AndroidRuntime(517): at java.lang.reflect.Method.invokeNative(Native Method)
11-02 22:07:19.615: E/AndroidRuntime(517): at java.lang.reflect.Method.invoke(Method.java:511)
11-02 22:07:19.615: E/AndroidRuntime(517): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
11-02 22:07:19.615: E/AndroidRuntime(517): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
11-02 22:07:19.615: E/AndroidRuntime(517): at dalvik.system.NativeStart.main(Native Method)
11-02 22:07:19.615: E/AndroidRuntime(517): Caused by: java.lang.IllegalArgumentException
11-02 22:07:19.615: E/AndroidRuntime(517): at android.os.PowerManager$WakeLock.<init>(PowerManager.java:250)
11-02 22:07:19.615: E/AndroidRuntime(517): at android.os.PowerManager.newWakeLock(PowerManager.java:446)
11-02 22:07:19.615: E/AndroidRuntime(517): at com.an.framework.impl.AndroidGame.onCreate(AndroidGame.java:50)
11-02 22:07:19.615: E/AndroidRuntime(517): at android.app.Activity.performCreate(Activity.java:4531)
11-02 22:07:19.615: E/AndroidRuntime(517): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1071)
11-02 22:07:19.615: E/AndroidRuntime(517): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2150)
11-02 22:07:19.615: E/AndroidRuntime(517): ... 11 more
这是我的清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.an.chess"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/ic_launcher" android:label="Chester" android:debuggable="true">
<activity android:name=".ChessGame"
android:label="Chess"
android:configChanges="keyboard|keyboardHidden|orientation"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8"/>
预先感谢您一直以来的支持!
最佳答案
问题是WakeLock
实例的创建。从android来源(API 14):
WakeLock(int flags, String tag)
{
switch (flags & LOCK_MASK) {
case PARTIAL_WAKE_LOCK:
case SCREEN_DIM_WAKE_LOCK:
case SCREEN_BRIGHT_WAKE_LOCK:
case FULL_WAKE_LOCK:
case PROXIMITY_SCREEN_OFF_WAKE_LOCK:
break;
default:
throw new IllegalArgumentException();
}
mFlags = flags;
mTag = tag;
mToken = new Binder();
}
因此,您传递给
android.os.PowerManager.newWakeLock
的标志无效。更新:
您必须使用上述任何标志(例如
PowerManager.FULL_WAKE_LOCK
)。您正在使用与LayoutParam
无关的WakeLock
常量。关于java - LogCat中的致命错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19747499/