Click here to Skip to main content
12,998,423 members (89,551 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I'm trying to build a project for an intro to java class where you have a library that you can add to and play music, kind of like a dumbed down iTunes. Unfortunately, after solving all of the syntax errors, I'm now getting one runtime when I open the savefiledialog. It won't show me files, only folders.

Here's my code:

//C:\\Users\\Andrew\\Downloads\\never gonna give you up.wav
//Andrew Douglas
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import javax.sound.sampled.*;
import javax.swing.filechooser.*;
import javax.swing.JTable;

//Creates class
public class JPlayer extends JFrame implements ActionListener {
	//Sets up form items and necessary globals
	JButton save, play, stop, loop;
	JFileChooser dialog;
	JTable table;
	String Artist, Song, Album, Loc;
	Object[][] data;
	int n = 1;
	//Makes the library, with a 51 song limit.
	JLibrary[] addedSong = new JLibrary[50];
	public JPlayer() {
		super ("JPlayer");
		//Creates frame
      	this.setSize(800, 600);
      	//Makes titles for table
      	String[] columnNames =  {"Artist",
        //Gives one value for array
        addedSong[0] = new JLibrary ("Rick Astley", "NGGYU", "UnKnown", "C:\\Users\\Andrew\\Downloads\\never gonna give you up.wav");
        //Adds it to table array
        Object[][] data = {
        	(addedSong[0].returnArtist()), (addedSong[0].returnSong()), (addedSong[0].returnAlbum()), (addedSong[0].returnFile())
		//Creates table
        table = new JTable(data, columnNames);
        table.setPreferredScrollableViewportSize(new Dimension(500, 70));
        //Lets it sort the rows
        //Creates the scroller
        JScrollPane scrollPane = new JScrollPane(table);
        //Makes the save file dialog and the play and save buttons
        dialog = new JFileChooser();
        play = new JButton ("Play Song");
        save = new JButton ("Save a file");
        //Adds the button listeners
        //Adds buttons to panel
        JPanel buttons = new JPanel();
        //Puts the buttons at the bottom
        add(buttons, BorderLayout.SOUTH);
	//Creates action listener for button
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == save) {
			dialog.setFileFilter(new FileNameExtensionFilter("WAV File", ".wav"));
			int returnVal = dialog.showSaveDialog(JPlayer.this);
            if (returnVal == dialog.APPROVE_OPTION) {
                File file = dialog.getSelectedFile();
                addToLibrary("", "", "", file.getName());
		else if (e.getSource() == play) {
			String holder2;
			Object holder;
			holder = table.getValueAt(table.getSelectedRow(), 3);
			try {
			File soundFile = new File(holder.toString());
			AudioInputStream audioIn = AudioSystem.getAudioInputStream(soundFile);
			Clip clip = AudioSystem.getClip();;
			} catch (UnsupportedAudioFileException f) {
      } catch (IOException f) {
      } catch (LineUnavailableException f) {
	} }
	public static void main(String[]args) {
		new JPlayer();
	public void addToLibrary(String art, String song, String alb, String file) {
			addedSong[n] = new JLibrary(art, song, alb, file);
			int j = 0;
			while (n >= 0) {
			Object[][] data = {
			j = j+1;
			n = n +1;

Any help would be appreciated, as I'm pretty new to this:)
Posted 19-Jun-13 5:23am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

See this tutorial[^] for a sample of this control. Note also that if there are no .wav files currently stored in your directories then you will only see folders listed.
Shubhashish_Mandal 20-Jun-13 2:25am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Richard MacCutchan 20-Jun-13 3:25am
Isn't that the same link I already provided?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 20 Jun 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100