Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException from example - fresh windows install processing 4.3 #36

Open
jmej opened this issue Dec 4, 2023 · 5 comments
Open

Comments

@jmej
Copy link

jmej commented Dec 4, 2023

I have run this example code on many installs of 4.3 using theMidiBus library from the package manager but on this particular system (windows 11 pro) I can't get the exmaple to run without a NullPointerException with no further information.

I tried downloading the latest library release manually but had the same problem.

@jmej
Copy link
Author

jmej commented Dec 4, 2023

the workaround mentioned here seems to work...

@AndresMartinM
Copy link

hi ✌️ i tried the examples, and apparently i fixed that problem in particular changing the parent of the MidiBus from 'this' to 'new java.lang.Object()'.
myBus = new MidiBus(new java.lang.Object(), -1, 3);
i'm using the processing library manager version of themidibus. i still have some other issues, but the nullpointerexception disappears

@fukuchi
Copy link

fukuchi commented Oct 29, 2024

There are other workarounds as shown below.

// myBus = new MidiBus(this, input, output);
myBus = new MidiBus();
myBus.registerParent(this);
myBus.addInput(input);
myBus.addOutput(output);

@vicente95650
Copy link

vicente95650 commented Dec 26, 2024

I had given up trying to find workaround for my NullPointerException problem when using Processing 4, and had gone back to Processing 3 until I found this simple workaround by fukuchi which works with Processing 4.3!
Replacing the file themidibus.jar did not fix my NullPointerException problem but using fukuchi's workaround did.
I am on macOS Sonoma on a mac studio with an apple processor.

In fact even the following simpler workaround works:
// myBus = new MidiBus(this, input, output);
myBus = new MidiBus(null, input, output); // don't directly specify this sketch as the parent
registerParent(this); // specify the sketch as parent

In fact the single-line workaround suggested by AndresMartinM also works:
myBus = new MidiBus(new java.lang.Object(), input, output); // a new instance of java.lang.Object, instead of this sketch, is the parent.

It appears that the essence of this workaround is to not directly specify this sketch as the parent when initializing the MidiBus object!

@donausoft
Copy link

This worked only partial for me:
myBus = new MidiBus(new java.lang.Object());

After using this or other similar lines, MidiBus worked only for output.
Not for input.

The solution for me was:

MidiReceiver receiver = new MidiReceiver();
myBus = new MidiBus(receiver);

public class MidiReceiver { 
    void noteOn(int channel, int pitch, int velocity) { /* ... */ }
    /* ... */
}

As mentioned here:
#28 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants