Problem running Java apps

Discussion in 'Mac Apps and Mac App Store' started by iGor, May 10, 2003.

  1. iGor macrumors newbie

    Joined:
    May 9, 2003
    #1
    I am new to Macs and am trying to run 1.4.1 apps from the terminal.

    javac myapp.java

    java myapp

    It uses java from 1.4.1 and the little java icon opens in the dock but nothing else happens and when I right click on the icon it offers force quit. The app is a simply JOptionPane Hello World so it shouldnt take long. println Hello World works fine. My applets work great in the browser.

    Any help would be appreciated.
     
  2. Wes macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #2
    Hi, I used to play with the terminal, but now I just use Project Builder (Dev. Tools) or JJ Edit. JJ Edit is a VERY simple program for compiling and running. Give it a try.

    http://homepage.mac.com/jmacmullin/
     
  3. lmalave macrumors 68000

    lmalave

    Joined:
    Nov 8, 2002
    Location:
    Chinatown NYC
    #3
    Hmm...weird. I guess it found the class, otherwise it would have given you a "class not found" error. Sounds like it might be a swing-related issue.

    Just to make sure, maybe try running a simpler class that just does a:

    System.out.println("Hello world!");

    And see what happens with that, that'll help you isolate the problem.
     
  4. Catfish_Man macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #4
    Re: Problem running Java apps

    Is it an applet? I believe they have to run using some sort of applet runner program (usually a browser, as you said). If not, try googling for how to force it back to 1.3.1 and see if that helps.
     
  5. iGor thread starter macrumors newbie

    Joined:
    May 9, 2003
    #5
    No. My applets work fine in Safari.

    I already tried that and it works fine. You may be right about a swing problem but I dont see why I would have one.

    My system is not tweaked, everythings vanilla from Apple. I *shouldnt* be having any problems :mad:

    Wes, I do not want to revert back to 1.3 and switching to jj edit or project builder is not a proper solution.

    Hmmm, another thing, a simple C Hello World app fails to compile as well. What the heck?
     
  6. Wes macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #6
    JJ edit is just a front end GUI and uses the usual Mac OS X compiler. So if you tried my solution I think you might isolate your problem.
     
  7. iGor thread starter macrumors newbie

    Joined:
    May 9, 2003
    #7
    I got 1.4.1 from Apple. Isnt this the usual/default for OSX?
     
  8. dflett macrumors newbie

    Joined:
    May 3, 2003
    Location:
    BXL
    #8
    To get a definitive answer, you will need to post the code (or a link to it) so us seasoned Java developers can take a look. Are you setting the size of the JWindow/JFrame?
     
  9. iGor thread starter macrumors newbie

    Joined:
    May 9, 2003
    #9
    It works now.

    Same exact code.

    I reinstalled X. Was going to anyways because Elements complained about UFS on my main partition.

    One question though, how do I get the java look rather than the aqua?
     
  10. Wes macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #10
    public static void main(String[] args) {
    try {
    UIManager.setLookAndFeel(
    UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception e) { }

    ...//Create and show the GUI...

    that help?
     
  11. iGor thread starter macrumors newbie

    Joined:
    May 9, 2003
    #11
    That code looks incomplete, here are my test bits


    Code:
    import javax.swing.JOptionPane;
    
    public class Test {
    
        public static void main( String args[] )
        {
    		    	JOptionPane.showMessageDialog( null, "Yay!");
    	
    	System.exit( 0 );
        }
    }
     
  12. Wes macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #12
    The code I posted was the code that gives swing the java look, not a complete app.
     
  13. iGor thread starter macrumors newbie

    Joined:
    May 9, 2003
  14. Wes macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London
    #14
    Maybe is has something to do with that fact that you didn't load all of swing (import javax.swing.*;).
     
  15. iGor thread starter macrumors newbie

    Joined:
    May 9, 2003
  16. Wes macrumors 68020

    Wes

    Joined:
    Jun 22, 2001
    Location:
    London

Share This Page