Hello,
I'm trying to run this code in Processing Android (processing 3.0.1, SDK 19)
// Vibrate Android via Processing
// Eric Pavey - www.akeric.com - 2010-10-24
// You must enable VIBRATE in Android -> Sketch Permissions menu!!!
// Imports:
import android.view.MotionEvent;
import android.content.Context;
import android.app.Notification;
import android.app.NotificationManager;
// Setup vibration globals:
NotificationManager gNotificationManager;
Notification gNotification;
long[] gVibrate = {0,250,50,125,50,62};
Context ctx;
void setup() {
size(displayWidth, displayHeight);
}
void draw() {
// do nothing...
}
//-----------------------------------------------------------------------------------------
// Override the parent (super) Activity class:
// States onCreate(), onStart(), and onStop() aren't called by the sketch. Processing is entered
// at the 'onResume()' state, and exits at the 'onPause()' state, so just override them as needed:
void onResume() {
super.onResume();
// Create our Notification Manager:
gNotificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
// Create our Notification that will do the vibration:
gNotification = new Notification();
// Set the vibration:
gNotification.vibrate = gVibrate;
}
//-----------------------------------------------------------------------------------------
// Override the parent (super) SurfaceView class to detect for touch events:
public boolean surfaceTouchEvent(MotionEvent event) {
// If user touches the screen, trigger vibration notification:
gNotificationManager.notify(1, gNotification);
return super.surfaceTouchEvent(event);
}
It used to work a few months ago, but now, I got this error:
FATAL EXCEPTION: main Process: processing.test.test_android_vibe, PID: 28363 java.lang.RuntimeException: Unable to resume activity {processing.test.test_android_vibe/processing.test.test_android_vibe.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2986) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3017) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392) at android.app.ActivityThread.access$800(ActivityThread.java:151) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
It seems that I have a problem with "Context", but impossible to find a solution. I have the same problem every time I use specific Android function into Processing (GeoLocation, soundPool, ...).