Java and TextMate and why

Discussion in 'Mac Programming' started by ifjake, Jan 16, 2007.

  1. macrumors 6502a

    Joined:
    Jan 19, 2004
    #1
    Beginner here.

    I've just started a Java course, and am considering getting TextMate to use for writing. I'm getting this stupid error for reasons I know not why. I can compile and run a little test Java app from the terminal just fine but when I try and do it from within TextMate it yells at me:
    Code:
    Exception in thread "main" java.util.NoSuchElementException
    	at java.util.Scanner.throwFor(Scanner.java:817)
    	at java.util.Scanner.next(Scanner.java:1431)
    	at java.util.Scanner.nextInt(Scanner.java:2040)
    	at java.util.Scanner.nextInt(Scanner.java:2000)
    	at testprogram.main(testprogram.java:6)
    So this is frustrating. Works fine from the terminal. Works fine from Xcode. I'd rather use TextMate if I could. Obviously there's something fundamental that I'm not getting. Maybe this isn't the best place to post this, but it seems like you guys are pretty kind to people who are new at this stuff.
     
  2. macrumors member

    Joined:
    Oct 27, 2003
    #2
    I mostly use TextMate for Ruby and Python development, and don't have it in front of me, so let me ask a few questions on how you are doing it.

    - How are you running it through TextMate?
    - What is the source code you are trying to run?

    Also, have you tried Eclipse?
     
  3. macrumors 6502

    Joined:
    Dec 6, 2006
    #3
    Can you post your code. It's impossible to diagnose what is wrong from an exception output in Java unless you see the exception in the context of the code.
     
  4. macrumors 6502

    Joined:
    Sep 15, 2006
    #4
    I'm fairly certain that this issue happened a while back - as long as you don't use any kind of scanner utilities you should be fine (no I/O) - just save the java file and compile it separetly and you'll do fine - this is 100% a textmate issue.

    Eclipse is great, but imo due to autocomplete and various configuration options you might not get as much "bang for your buck" as you would with something a lot more basic - so good luck with your future career in programming :)
     
  5. macrumors 6502

    Joined:
    May 12, 2003
    #5
    I don't know this for sure, but I believe that the TextMate console is read-only. It doesn't support keyboard input. Your code is probably assuming that the ability to get input is there.

    As others have said, if you want a definitive answer, post your code.
     
  6. thread starter macrumors 6502a

    Joined:
    Jan 19, 2004
    #6
    This is probably the case. It appears there's an option to run the class file through the Terminal when I look editing the Java bundle, but it's in this block of code and I'm not sure what to comment or uncomment.

    Here's the code for good measure. Thanks for your all's help.

    Code:
    import java.util.Scanner;
    class squareroot {
            public static void main(String[] args) {
                    Scanner kb = new Scanner(System.in);
                    System.out.print("Enter a number: ");
                    int n = kb.nextInt();
                    double r, guess = n/2.0;
                    for(int i = 0; i < 10; i++) {
                            r = n/guess;
                            guess = (guess + r)/2.0;
                    }
                    System.out.printf("Square root of %d equals %.2f%n", n, guess);
            }
    }
     
  7. macrumors 6502

    Joined:
    Sep 15, 2006
    #7
    without system.in you can't do much - no "guessing" or anything (whatever you intend to do with your application)- you can't enter any kind of data and thus you can't really debug it.

    Instead do like this: open your terminal, find your way to your java document, compile and run - javac *filnename* && java filenamewithout.class
    This is by far the best solution imo.
     
  8. macrumors 6502

    Joined:
    May 12, 2003
    #8
    Your code pretty much confirms my suspicions. If you want to get input from System.in, you'll have to do that outside of TextMate.
     
  9. thread starter macrumors 6502a

    Joined:
    Jan 19, 2004
    #9
    It's just a little thing that finds the square root of whatever number you put in, just for fun. And I agree, your suggestion is by far the best solution. Thanks for the help.

    And thanks everyone else. I'm set for class now. (PC? We don't need no stinkin' PC!)
     
  10. macrumors 68040

    iW00t

    Joined:
    Nov 7, 2006
    Location:
    Defenders of Apple Guild
    #10
    Why not Eclipse?

    There is a standard OS X port too.
     
  11. macrumors 6502

    Joined:
    Dec 6, 2006
    #11
    ifjake doesn't state what Mac he/she is using. On an Intel Mac Eclipse is rather nippy. On a PPC Mac (unless it a 2Ghz> G5) it runs like treacle. Using Eclipse for small programs is like using a sledge hammer to open a wallnut.
     
  12. thread starter macrumors 6502a

    Joined:
    Jan 19, 2004
    #12
    Yeah, these are probably going to be small homework projects to be completed a week after given. And no intel or G5 here.

    (nippy? treacle? I now know two new words. Sweet!)
     
  13. macrumors 6502

    Joined:
    Sep 15, 2006
    #13
    well I use eclipse as well, however when you are beginning the coding endevour it's a lot better to go "dirty" and type eveything by hand - no autocomplete, no easy mode, once you've done your homework and understand what kind of issues is generated by what you can move slowly towards more advanced editors (such as eclipse), this is how I recieved my schooling in my current university and it worked for me :)
     
  14. macrumors 603

    jeremy.king

    Joined:
    Jul 23, 2002
    Location:
    Fuquay Varina, NC
    #14
    You could try changing the bundle compile and run plist

    from
    Code:
    { java -Dfile.encoding=utf-8 "${TM_FILENAME%.java}"
      echo -e "\nProgram exited with status $?."; }|pre
    
    # # if you want to run the program in Terminal.app
    # osascript <<EOF
    #    tell application "Terminal"
    #       activate
    #       do script "cd '$TM_DIRECTORY'; java '${TM_FILENAME%.java}'"
    #    end tell
    # EOF
    
    to
    Code:
    #{ java -Dfile.encoding=utf-8 "${TM_FILENAME%.java}"
    #  echo -e "\nProgram exited with status $?."; }|pre
    
    # # if you want to run the program in Terminal.app
     osascript <<EOF
        tell application "Terminal"
           activate
           do script "cd '$TM_DIRECTORY'; java '${TM_FILENAME%.java}'"
        end tell
     EOF
    
    Good Luck, let me know how it works.

    PS. If you want to look at other options, check out Netbean BlueJ edition
     
  15. thread starter macrumors 6502a

    Joined:
    Jan 19, 2004
    #15
    Yeah that worked. I had tried that but failed to realize I had to comment the previous two lines. BlueJ looks interesting. I'll have to mess with that some. Thanks.
     

Share This Page