Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: I need help with fixing the exceptions in my Program.

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need help with fixing the exceptions in my Program.

    My program is as follows and I have used the JMF2.2.1e Libraries. I have written my program using JavaFX that creates a new instance of the MP3 song with the following functions: play, stop, next, previous choose from where to get the song from. I need help fixing my program to do with the exception. Please help me. Regards
    package javafxapplication2;
     
    import java.awt.Component;
    import java.awt.GridLayout;
    import java.awt.PopupMenu;
    import java.awt.event.ActionListener;
    import javafx.application.Application;
    import javafx.event.ActionEvent;
    import javafx.stage.Stage;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.util.Vector;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JPanel;
    import javax.swing.filechooser.FileFilter;
    import static sun.audio.AudioPlayer.player;
     
    public class JavaFXApplication2 extends Application implements ActionListener  {
     
    	public JavaFXApplication2 (PopupMenu exit_f, PopupMenu open_f, JButton play_btn, JButton next_btn, JButton stop_btn, Vector list)
    	{
    		JMenu file=new JMenu("File");
     
     
     
    		open_f.addActionListener ((ActionListener) this);
    		exit_f.addActionListener ((ActionListener) this);
     
     
    		file.add (open_f);
    		file.add (exit_f);
     
     
     
    		JMenuBar bar=new JMenuBar();
    		bar.add (file);
     
     
    		play_btn=new JButton("PLAY");
    		next_btn=new JButton("NEXT");
    		stop_btn=new JButton("STOP");
    		next_btn.setEnabled (false);
    		stop_btn.setEnabled (false);
    		JPanel panel=new JPanel(new GridLayout(1,3));
     
    		panel.add (play_btn);
    		panel.add(next_btn);
    		panel.add(stop_btn);
     
    		//File f=new File("c:/ksm/mp3");
    		list=new Vector(1,1);
     
    		play_btn.addActionListener(this);
    		next_btn.addActionListener(this);
    		stop_btn.addActionListener(this);
     
     
     
     
     
     
    	}
     
        private JavaFXApplication2() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
     
            public void actionPerformed (ActionEvent e, Object exit_f, Object open_f)
    	{
     
     
    		{
    			play_btn.setEnabled (false);
    			next_btn.setEnabled (true);
    			stop_btn.setEnabled (true);
                        int count = 0;
    			play(count);
     
     
                        if(count==list.size()-1)
    			{
    				count=0;
     
    			}
     
    			else 
    			{
    				count++;
    			}
    			play(count);
     
     
    			player.stop ();
    			play_btn.setEnabled (true);
    			next_btn.setEnabled (false);
    			stop_btn.setEnabled (false);
     
    		}
    		if(e.getSource ()==open_f)
    		{
    			System.out.println("in open_f event");
    			open();
    		}
    			if(e.getSource ()==exit_f)
    		{
    			System.out.println("in exit_f event");
    		}
     
     
    	}
            public void play(int v, boolean status)
    	{
    		if(status==true)
    		{
    			player.stop();
    			status=false;
    		}
     
    		if(status==false)
    		{
    			try
    			{
    				player.start();
    				status=true;
    			}
    			catch(Exception murle)
    			{
    				System.out.println("in murle");
    			}
    		}
     
    	}
    	public void open(FileFilter FileFilter, Component open_f)
    	 {
    	 	JFileChooser fc=new JFileChooser(".mp3");
    	 	fc.setFileSelectionMode (JFileChooser.FILES_ONLY);
    	 	try {
    			FileReader filter=new FileReader("mp3");
    		} catch (FileNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	 	fc.addChoosableFileFilter(FileFilter);
    	 	int result=fc.showOpenDialog (open_f);
    	 	if(result==JFileChooser.APPROVE_OPTION)
    	 	{
    	 		File f=fc.getSelectedFile ();
    	 		if(f.exists ()==true && f.isFile ()==true)
    	 		{
     
    	 			list.add (f);
    	 			for(int i=0;i<list.size ();i++)
    	 			{
    	 				System.out.println(list.get (i));
    	 			}
    	 		}
    	 		else {
                             }
    	 	}
     
    	 }
     
    {
    		JavaFXApplication2 obj=new JavaFXApplication2();
    		obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	}
     
     
        public void setDefaultCloseOperation(int EXIT_ON_CLOSE) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
     
        private void open() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
     
        private void play(int count) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
     
        @Override
        public void start(Stage stage) throws Exception {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
     
        @Override
        public void actionPerformed(java.awt.event.ActionEvent ae) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
     
        private static class Player {
     
            public Player() {
    	boolean status=false;
            }
     
        private static class list {
     
            private static void add(File f) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
     
            private static int size() {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
     
            private static boolean get(int i) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
     
            public list() {
            }
        }
     
        private static class stop_btn {
     
            private static void setEnabled(boolean b) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
     
            public stop_btn() {
            }
        }
     
        private static class next_btn {
     
            private static void setEnabled(boolean b) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
     
            public next_btn() {
            }
        }
     
        private static class play_btn {
     
            public play_btn() {
            }
     
        }
    }
     
        private class JavaFXApplication2Impl extends JavaFXApplication2 {
     
            public JavaFXApplication2Impl(PopupMenu exit_f, PopupMenu open_f, JButton play_btn, JButton next_btn, JButton stop_btn, Vector list) {
                super(exit_f, open_f, play_btn, next_btn, stop_btn, list);
            }
     
            @Override
            public void actionPerformed(java.awt.event.ActionEvent ae) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
     
                        @Override
                        public void start(Stage stage) throws Exception {
                            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
                        }
     
            private void player() {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
        }
     
        private static class list {
     
            private static boolean get(int i) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
     
            private static int size() {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
     
            private static void add(File f) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
     
            public list() {
            }
        }
     
        private static class play_btn {
     
            private static void setEnabled(boolean b) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
     
            public play_btn() {
            }
        }
     
        private static class next_btn {
     
            private static void setEnabled(boolean b) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
     
            public next_btn() {
            }
        }
     
        private static class stop_btn {
     
            private static void setEnabled(boolean b) {
                throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
            }
     
     
        }
     
    }

    Output in Netbeans (IDE):
    "Executing C:\***
    using platform C:\Program Files\Java\jdk\jre/bin/java
    Exception in Application constructor
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.javafx.main.Main.launchApp(Main.java:698)
    at com.javafx.main.Main.main(Main.java:871)
    Caused by: java.lang.RuntimeException: Unable to construct Application instance: class javafxapplication2.JavaFXApplication2
    at com.sun.javafx.application.LauncherImpl.launchAppl ication1(LauncherImpl.java:393)
    at com.sun.javafx.application.LauncherImpl.access$000 (LauncherImpl.java:47)
    at com.sun.javafx.application.LauncherImpl$1.run(Laun cherImpl.java:115)
    at java.lang.Thread.run(Thread.java:744)
    Caused by: java.lang.NoSuchMethodException: javafxapplication2.JavaFXApplication2.<init>()
    at java.lang.Class.getConstructor0(Class.java:2810)
    at java.lang.Class.getConstructor(Class.java:1718)
    at com.sun.javafx.application.LauncherImpl.launchAppl ication1(LauncherImpl.java:275)
    ... 3 more
    Java Result: 1
    Deleting directory C:\****
    jfxsa-run:
    BUILD SUCCESSFUL (total time: 7 seconds)"

    The Pop Up error from the runnable JavaFX file says "Exception while running Application"
    Last edited by ShafeeBhula; December 28th, 2013 at 08:23 PM. Reason: Code Fixes


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: I need help with setting my main method.

    Welcome to the forum.

    Please read this topic to learn how to post code in code or highlight tags and other useful info for newcomers.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I need help with setting my main method.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    Please copy the full text of the compiler's error messages and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Dec 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need help with setting my main method.

    I have done that exactly. Thank you for your advice.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I need help with fixing the exceptions in my Program.

    How do you start execution of the class? I do not see a main() method.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: I need help with fixing the exceptions in my Program.

    @Norm: The details of running the application are built into the Application class. There could also be a main() method to provide "standalone" functionality, but it's not necessary.

    @ShafeeBhul: Is your Netbeans IDE properly set up to run JavaFX applications? At least Java 7 and/or the legacy JavaFX library somewhere in the classpath? Java 7 or better specified as the build environment? JavaFX is changing so rapidly that if you aren't using the latest version of Java, even the legacy library may not work. I don't have the AudioPlayer library, but your code seems to be okay in my JavaFX environment, so I'm thinking yours may not be correct (but I could be wrong).

  7. #7
    Junior Member
    Join Date
    Dec 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need help with fixing the exceptions in my Program.

    I am using Netbeans IDE 7.4; Java SDK is 7 45 64bit; Java RE 1.7.0_45; Java HotSpot(TM) 64-Bit Server VM 24.45-b08; Windows 8.1 on a custom AMD PC. My class-path has not been set up how would I set it up correctly.

  8. #8
    Junior Member
    Join Date
    Dec 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need help with fixing the exceptions in my Program.

    I don't require a main() method in my program. Please could you assist in fixing my program. I am not sure where I went wrong.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: I need help with fixing the exceptions in my Program.

    Sorry, I don't know anything about javafx programs.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. information on main method
    By antoni in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 10th, 2013, 10:30 PM
  2. Main Method Error
    By KMCD00 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: July 16th, 2013, 01:55 AM
  3. Doesnt have Main Method?
    By connorlm3 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 26th, 2013, 02:42 PM
  4. Replies: 3
    Last Post: October 31st, 2011, 12:42 AM
  5. How do I call a method from the main method?
    By JavaStudent1988 in forum Java Theory & Questions
    Replies: 5
    Last Post: October 19th, 2011, 08:37 PM

Tags for this Thread