I don't know why I'm getting this error, I've spent about two hours trying to locate the source, but I just keep going round in circles. Could you have a quick look and see anything wrong?
WakeLock Code:-
wakeLock = powerManager.newWakeLock(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, "GLGame");
Here's the LogCat output:-
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
Here's my Manifest file:-
<?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"/>
Thank you in advance for your kind support all the time!
The problem is the creation of the WakeLock
instance. From the android sources (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();
}
So the flags you pass to android.os.PowerManager.newWakeLock
are invalid.
Update:
You must use any of the above flags (e.g. PowerManager.FULL_WAKE_LOCK
). You are using a LayoutParam
constant which is unrelated to WakeLock
.