Results 1 to 11 of 11
  1. #1
    grahamcrackeh is offline Member
    Join Date
    Mar 2011
    Posts
    11
    Rep Power
    0

    Default Adding midi devices to and array

    I want to add the names of all connected midi devices in and array to be used with a JComboBox and Im not sure why Im getting an error on this code

    MidiDevice.Info[] info = MidiSystem.getMidiDeviceInfo();
    for(int counter = 0; counter < info.length; counter++){
    midiDeviceNames[counter] = info[counter].getName();
    }

  2. #2
    Join Date
    Mar 2011
    Posts
    94
    Rep Power
    0

    Default

    Well what is the exact error you are getting? I'm going with NullPointerException.

  3. #3
    grahamcrackeh is offline Member
    Join Date
    Mar 2011
    Posts
    11
    Rep Power
    0

    Default

    You are correct... So any suggestions?

  4. #4
    Join Date
    Mar 2011
    Posts
    94
    Rep Power
    0

    Default

    Look at this method and see if it is actually returning the array that you expect:
    Java Code:
    MidiSystem.getMidiDeviceInfo();

  5. #5
    grahamcrackeh is offline Member
    Join Date
    Mar 2011
    Posts
    11
    Rep Power
    0

    Default

    it returns the names i wanted... so i changed the code to this...

    MidiDevice.Info[] midiDeviceNames = MidiSystem.getMidiDeviceInfo();

    and put that array in the combobox... still that same error:mad:

  6. #6
    Join Date
    Mar 2011
    Posts
    94
    Rep Power
    0

    Default

    Can you post the full error (as well as the code for that method)?

  7. #7
    grahamcrackeh is offline Member
    Join Date
    Mar 2011
    Posts
    11
    Rep Power
    0

    Default

    public void updateDevices(){
    MidiDevice.Info[] info = MidiSystem.getMidiDeviceInfo();
    for(int counter = 0; counter < info.length; counter++){
    midiDeviceNames[counter] = info[counter].getName();
    }
    }


    Exception in thread "main" java.lang.NullPointerException
    at javax.swing.DefaultComboBoxModel.<init>(Unknown Source)
    at javax.swing.JComboBox.<init>(Unknown Source)
    at com.grahamcrackeh.launchpadmonome.Gui.<init>(Gui.j ava:61)
    at com.grahamcrackeh.launchpadmonome.Main.main(Main.j ava:7)

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    That's not the code that's throwing the error. Read the stack trace. What's at line 61 in the constructor of the Gui class? Where are the variables dereferenced on that line initialized?

    db

  9. #9
    grahamcrackeh is offline Member
    Join Date
    Mar 2011
    Posts
    11
    Rep Power
    0

    Default

    this:

    midiDeviceChooser1 = new JComboBox(midiDeviceNames);

  10. #10
    grahamcrackeh is offline Member
    Join Date
    Mar 2011
    Posts
    11
    Rep Power
    0

    Default

    Please Help. Bump.

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    :headdesk:
    Where are the variables dereferenced on that line initialized? Where did you initialize midiDeviceNames? Before or after line 61 is reached?

    To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem.

    Use code tags to post codes -- [code]CODE[/code] will display as
    Java Code:
    CODE
    Or paste your code between a pair of {code} tags.

    Also, read through How to ask questions the smart way.

    db

Similar Threads

  1. Sensing MIDI devices fails on OSX 10.6.6
    By grrreg in forum New To Java
    Replies: 1
    Last Post: 02-07-2011, 11:01 PM
  2. Array always adding to 0???
    By Javawizard in forum New To Java
    Replies: 6
    Last Post: 11-13-2010, 11:02 PM
  3. adding in array String
    By Mekonom in forum New To Java
    Replies: 4
    Last Post: 12-10-2009, 04:28 PM
  4. Getting input from MIDI devices on a Mac
    By Ben Wheatley in forum Advanced Java
    Replies: 1
    Last Post: 08-05-2009, 06:08 PM
  5. adding to an array
    By mayhewj7 in forum New To Java
    Replies: 14
    Last Post: 02-19-2009, 05:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •