Results 1 to 18 of 18
  1. #1
    B.Hennessy is offline Member
    Join Date
    Jan 2015
    Location
    Dublin,Ireland
    Posts
    10
    Rep Power
    0

    Post Will compile but wont open for me can anyone out there help me out. im new to this ga

    hey i wrote this code up in college and it works fine. When i came home and tried it on my laptop it wont open. java compiles then wont go further. has any one else exp this .

    Java Code:
    import java.util.Random;
    import javax.swing.*;
    import java.awt.event.* ;
    
    class Magic8ball extends JFrame implements ActionListener
    
    {	
    	
            JPanel pnl = new JPanel();
            ClassLoader ldr = this.getClass().getClassLoader();
            ImageIcon ball = new ImageIcon( ldr.getResource("8ball.png"));
            JLabel lbl1 = new JLabel (ball);
    		JLabel lbl2 = new JLabel ("Magic 8 ball is a program I have created with java.");
    		JLabel lbl3 = new JLabel(ball , JLabel.CENTER);
    		JButton btn1 = new JButton("Shake Me");
    
    	
    		
    		
             public Magic8ball()
    	 {
    		super(" magic 8 ball ");
    		setSize(500 , 200);
    		setDefaultCloseOperation( EXIT_ON_CLOSE);
    		add(pnl);
    		pnl.add (lbl1);	
    		pnl.add (lbl2);
            pnl.add (lbl3);	
    		pnl.add(btn1);
    		btn1.addActionListener (this);
    		setVisible(true);
    	 }
    	public static void main (String[] args)
    	{
        Magic8ball gui = new Magic8ball();
    		}
    	
    	public void actionPerformed(ActionEvent event)
    	{
    			
    			Random r = new Random();
    
    		    int choice = 1 + r.nextInt(20);
    		    String response = "";
    		
    		if (choice == 1)
    			response = " Of coarse my friend ";
    	else if (choice == 2)
    			response = " yes , if you really believe ";
    	else if (choice == 3)
    			response = " only on sunny days i'm afraid ";
    	else if (choice == 4)
    			response = " yes , if you really believe ";
    	else if (choice == 5)
    			response = " maybe so , maybe not ";
    	else if (choice == 6)
    			response = " before the day breaks would be my advise ";
    	else if (choice == 7)
    			response = " keep running and do not stop ";
    	else if (choice == 8)
    			response = " Sorry I do not understand ";
    	else if (choice == 9)
    			response = " Can you repeat that in English please ";
    	else if (choice == 10)
    			response = " why do you continue to push my buttons ";
    	else if (choice == 11)
    			response = " if its raining do not forget your jacket ";
    	else if (choice == 12)
    			response = " yes , if you really believe ";
    	else if (choice == 13)
    		    response = " today will be sunny and hot , I wish ";
    	else if (choice == 14)
    			response = " most defenitly not ";
    	else if (choice == 15)
    			response = " never in a million year's pal ";
    	else if (choice == 16)
    			response = " if you try hard enough then yes ";
    	else if (choice == 17)
    			response = " go lower your head , that question was ridiculous ";
    	else if (choice == 18)
    			response = " that depends how much you want ";
    	else if (choice == 19)
    			response = " no it wont ever happing for you ";
    	else if (choice == 20)
    			response = " thats a question for your parents ";
    	else 
                response = "8-BALL ERROR!";
    		if ( event.getSource() == btn1)
    			{
    				JOptionPane.showMessageDialog(this , "8ball..."+response,"Message Dialog" , JOptionPane.INFORMATION_MESSAGE);
    			}
    	}
    }
    Last edited by JosAH; 01-25-2015 at 04:43 PM. Reason: added [code] ... [/code] tags

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    Quote Originally Posted by B.Hennessy View Post
    java compiles then wont go further.
    Is it one strike, or what? Please give a bit more detail.

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    B.Hennessy is offline Member
    Join Date
    Jan 2015
    Location
    Dublin,Ireland
    Posts
    10
    Rep Power
    0

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    Im not sure what that means. its my magic 8 ball assignment. in my windows cmd i enter javac Magic8ballwindow.java and it compiles with out errors but then when i enter java Magic8ballwindow.java it sends back error.

    D:\>javac Magic8ballwindow.java

    D:\>java Magic8ballwindow.java
    Error: Could not find or load main class Magic8ballwindow.java

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    When you execute with the java command, omit the program suffix (i.e. .java).

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    B.Hennessy is offline Member
    Join Date
    Jan 2015
    Location
    Dublin,Ireland
    Posts
    10
    Rep Power
    0

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    I received this now when i enter java Magic8ball


    D:\>javac Magic8ballwindow.java

    D:\>java Magic8ball
    Exception in thread "main" java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(ImageIcon.java:217)
    at Magic8ball.<init>(Magic8ballwindow.java:11)
    at Magic8ball.main(Magic8ballwindow.java:35)

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    I am confused. What is Magic8ball? What about

    java Magic8ballwindow

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  7. #7
    B.Hennessy is offline Member
    Join Date
    Jan 2015
    Location
    Dublin,Ireland
    Posts
    10
    Rep Power
    0

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    im also confused jim . worked fine in college on friday

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    Exception in thread "main" java.lang.NullPointerException
    at javax.swing.ImageIcon.<init>(ImageIcon.java:217)
    at Magic8ball.<init>(Magic8ballwindow.java:11)
    at Magic8ball.main(Magic8ballwindow.java:35)
    What has the null value on line 11?
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    Quote Originally Posted by B.Hennessy View Post
    im also confused jim . worked fine in college on friday
    My confusion was that you compiled one program but tried to run another. Your posts are inconsistent. Try it again and post exactly what you did and what the errors are. And does your source code include a package definition?

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  10. #10
    B.Hennessy is offline Member
    Join Date
    Jan 2015
    Location
    Dublin,Ireland
    Posts
    10
    Rep Power
    0

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    that list of code above is my assignment for college. to construct a magic 8 ball that consists of 20 random answers wen you click the button.
    we must compile it to check for errors then open it with the CMD also.
    When i enter javac Magig8ballwindow.java in CMD it works fine , no errors.
    So then to open it we must use CMD and enter java Magic8ball , thats were im getting my error. it cand find someting or theres a problem.
    it worked on pc in college on friday. tryed it on my laptop today and this happined. im not long at this stuffso its gettin confusing

  11. #11
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    Did you put the 8ball.png in the same location? Your program may not be able to find it.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  12. #12
    B.Hennessy is offline Member
    Join Date
    Jan 2015
    Location
    Dublin,Ireland
    Posts
    10
    Rep Power
    0

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    yes i have the image saved in the same folder as the program :/

  13. #13
    B.Hennessy is offline Member
    Join Date
    Jan 2015
    Location
    Dublin,Ireland
    Posts
    10
    Rep Power
    0

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    new error now ????

    D:\Computer Programming>java Magic8ballwindow.java
    Error: Could not find or load main class Magic8ballwindow.java

  14. #14
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    Quote Originally Posted by B.Hennessy View Post
    new error now ????

    D:\Computer Programming>java Magic8ballwindow.java
    Error: Could not find or load main class Magic8ballwindow.java
    You are doing it again. You are not keeping your names straight. Please do the following for clarity. Change your file name to match the internal class name. In this case, Magic8ball.java. Once you renamed the file, do the following:

    javac Magic8ball.java
    then
    java Magic8ball

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  15. #15
    B.Hennessy is offline Member
    Join Date
    Jan 2015
    Location
    Dublin,Ireland
    Posts
    10
    Rep Power
    0

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    they are named the same ..

  16. #16
    B.Hennessy is offline Member
    Join Date
    Jan 2015
    Location
    Dublin,Ireland
    Posts
    10
    Rep Power
    0

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    jim my deepist appolagies i see were i went wrong . im such a dumbass. thanks alot guys for all the help

  17. #17
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    Quote Originally Posted by B.Hennessy View Post
    jim my deepist appolagies i see were i went wrong . im such a dumbass. thanks alot guys for all the help
    No problem but you should let the forum know so others may benefit.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  18. #18
    B.Hennessy is offline Member
    Join Date
    Jan 2015
    Location
    Dublin,Ireland
    Posts
    10
    Rep Power
    0

    Default Re: Will compile but wont open for me can anyone out there help me out. im new to thi

    The problem i was having here was that tne name of my program was different to its name inside the program so my computer was having trouble finding it . noob mistake i quess. thanks everyone

Similar Threads

  1. Why wont this compile??
    By deeznatez in forum NetBeans
    Replies: 2
    Last Post: 10-05-2012, 08:54 AM
  2. Able to compile OK, But wont run..Help
    By subiedude101 in forum New To Java
    Replies: 2
    Last Post: 02-20-2011, 08:37 PM
  3. This one wont compile either.. any tips?
    By Student101 in forum New To Java
    Replies: 9
    Last Post: 11-18-2010, 05:49 AM
  4. Why wont this compile?
    By Student101 in forum New To Java
    Replies: 8
    Last Post: 11-18-2010, 05:33 AM
  5. why wont it compile
    By bje98f in forum Advanced Java
    Replies: 1
    Last Post: 04-23-2009, 10:55 PM

Posting Permissions

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