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 6 of 6

Thread: Need some help with OSX Java (Terminal)

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need some help with OSX Java (Terminal)

    I've recently switched to a mac book and am attempting to compile and run some of my old java scripts to figure out how everything works with the mac and terminal.

    Anyhow while I use the javac command I am getting tons of errors. Very basic simple coding is giving me upwards of 100 errors for basic loops. What am I doing wrong?


    Here is the my command:

    Matthew-lastname-MacBook-Pro-2:~ Matt$ javac Documents/Professional/java/LabOneAssignment.java
    Documents/Professional/java/LabOneAssignment.java:20: illegal character: \0

    ^
    Documents/Professional/java/LabOneAssignment.java:20: illegal character: \0

    ^
    Documents/Professional/java/LabOneAssignment.java:20: illegal character: \0

    ^
    Documents/Professional/java/LabOneAssignment.java:20: illegal character: \0

    (this error x 100 with ^ carrot gradually moving over)


    Very very basic code I'm testing this with:


    /**
    * This is the main method for this class
    *
    *
    * @author XXXXXX
    * @param args
    */

    public class LabOneAssignment {
    public static void main(String[] args) {
    int one;
    String name;
    one = 25;
    name = "Fred";
    System.out.println("The integer is: " + one + "\n"
    + "The name is: " + name);
    }
    }

    here is some more info:


    machine:~ Matt$ java -cp ./ testcheck.java

    Exception in thread "main" java.lang.NoClassDefFoundError: testcheck/java

    Caused by: java.lang.ClassNotFoundException: testcheck.java
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 48)


    would it make a difference if the files were written on windows in jEdit and then transferred to OSX? The path still points to them unless its an issue with the text file itself...
    Last edited by mkoop; January 14th, 2011 at 01:15 AM.


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Need some help with OSX Java (Terminal)

    I don't think it likes your "\n". Perhaps it's treating it as an escape character.

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some help with OSX Java (Terminal)

    I'm at a loss, I tried to compile this simple code as well:

    machine:~ Matt$ javac Documents/java/testcheck.java

    /**
    * This is the first class in the first lab of the first semester of Java!
    *
    * @author XXXX
    *
    */
    public class testcheck {

    /**
    * This is the main method for this class
    *
    * @param args
    */
    public static void main(String[] args) {

    System.out.println("Hi there!");

    }

    }


    Resulted in the same errors as above...

    Since trying this on my mac book I have gotten errors such as this, but compiling / running with DOS has worked as intended.

    additional info:

    All scripting was done in jEdit

    machine::~ Matt$ java -version
    java version "1.6.0_20"
    Java(TM) SE Runtime Environment (build 1.6.0_20-b02-279-10M3065)
    Java HotSpot(TM) 64-Bit Server VM (build 16.3-b01-279, mixed mode)

    I'll try to move code to eclipse and compile it through that and see if it will bipass this all but I really have no idea why this isn't working.

    It's as if I don't have the development kit, but with java native on OS X I should have everything I need?
    Last edited by mkoop; January 14th, 2011 at 01:46 AM.

  4. #4
    Junior Member
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some help with OSX Java (Terminal)

    I have figured out the problem. I originally wrote these codes in jEdit (Windows). I transferred the files to OS X and opened them, edited them and even re saved them overwriting the previous files. It was not until I made completely new files and cut the code, pasted it into a word pad and then into jEdit.

    Just a weird oddity I guess... several hours later...
    Last edited by mkoop; January 14th, 2011 at 05:39 AM.

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Need some help with OSX Java (Terminal)

    Windows machines add different line separators than unix/mac (\r\n vs \n)...pass the same file onto a mac and the file might not behave properly (this can get to be serious pain in other situations - such as writing a perl/php script on windows to transfer and run on a linux server)
    Last edited by copeg; January 14th, 2011 at 10:37 AM.

  6. #6
    Member DavidFongs's Avatar
    Join Date
    Oct 2010
    Location
    Minneapolis, MN
    Posts
    107
    Thanks
    1
    Thanked 45 Times in 41 Posts

    Default Re: Need some help with OSX Java (Terminal)

    On other OS's based on linux/unix (like OS X is) I've used the command dos2Unix to remedy this.

    Not sure if that command comes standard with OS X or not, but if not you can probably add it.