Java userNodeForPackage function fails under Matlab on OS X
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
When instantiating a Java class (a simple example is copied below) that calls the function java.utils.prefs.Preferences.userNodeForPackage(), matlab reports the following error:
??? Java exception occurred: java.lang.NullPointerException at java.util.prefs.AbstractPreferences.node(AbstractPreferences.java:817) at java.util.prefs.AbstractPreferences.node(AbstractPreferences.java:800) at java.util.prefs.Preferences.userNodeForPackage(Preferences.java:358)
This appears to happen only on Mac OS X (10.5.8 or 10.6.6), but not on Windows. I am using Matlab R2010b. The error prevents me from running a large and useful application (Micro-Manager) within Matlab. Does anyone have ideas how to fix this?
Thanks!
Nico
package matlabprefstest; import java.util.prefs.Preferences;
public class PrefsInst { public PrefsInst() { Preferences pf = Preferences.userNodeForPackage(this.getClass()); } }
0 Commenti
Risposte (2)
Samer Abdallah
il 21 Lug 2011
I'm having this problem too. In my case, I am trying to use the JavaSound MIDI system from Matlab. I have added a MIDI service provider (here: http://www.humatic.de/htools/mmj.htm) that gives better access to MIDI devices on Mac OS X. The MMJ code is trying to access its preferences via the java.lang.prefs system. This fails with a null pointer exception:
??? Java exception occurred:
java.lang.NullPointerException
at java.util.prefs.AbstractPreferences.node(AbstractPreferences.java:817)
at java.util.prefs.AbstractPreferences.node(AbstractPreferences.java:796)
at de.humatic.mmj.MidiSystem.getActiveSensing(MidiSystem.java:538)
at de.humatic.mmj.MidiSystem.initCallback(Native Method)
at de.humatic.mmj.MidiSystem.initMidiSystem(MidiSystem.java:107)
at de.humatic.mmj.MidiSystem.getInputs(MidiSystem.java:327)
at de.humatic.mmj.spi.CoreMidiProvider.getDeviceInfo(CoreMidiProvider.java:40)
at javax.sound.midi.MidiSystem.getMidiDeviceInfo(MidiSystem.java:173)
This completely disables the entire Java MIDI subsystem. I realise this is not exactly like the above report, but it looks closely related. I am able to reproduce the OPs report using a small Java function that calls Class.forName and Preferences.userNodeForPackage. The same problems occurs whatever class I give, eg:
>> samer.util.Util.userNodeForPackage('java.lang.Object')
Looking up preferences for class class java.lang.Object
??? Java exception occurred:
java.lang.NullPointerException
at java.util.prefs.AbstractPreferences.node(AbstractPreferences.java:817)
at java.util.prefs.AbstractPreferences.node(AbstractPreferences.java:800)
at java.util.prefs.Preferences.userNodeForPackage(Preferences.java:358)
at org.samer.util.Util.userNodeForPackage(Util.java:9)
Note that the problem is not with getting the Class object to pass as a parameter to Preferences.userNodeForPackage() - this is checked in my utility function and the Class object is not null.
cheers, Samer
ps. I am using Matlab Version 7.9.0.529 (R2009b) 64-bit (maci64).
0 Commenti
Richard Alcock
il 21 Lug 2011
Are your classes on the "dynamic" or "static" class path? If they are currently on the dynamic class path (for example, you used javaaddpath) what happens if you add them to the static class path?
0 Commenti
Vedere anche
Categorie
Scopri di più su Call Java from MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!