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...
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.
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?
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...
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)
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.