compilation - Java Will Not Compile Objects Created by Me -
i have been getting java compile error every time try compile code creates instance of class have created.  i've tried compiling manually, compiling different location, , tried compiling in safe mode.   have reinstalled java on computer.  here's example of code write , error get:
 instance creator class:
public class nothing {     public static void main(string args[]) {         can world = new can();     } }   instantiated class:
public class can {     public can() {         system.out.println("test");     } }   the compile error:
nothing.java:4: cannot find symbol symbol  : class can location: class nothing         can world = new can();         ^ nothing.java:4: cannot find symbol symbol  : class can location: class nothing         can world = new can();                         ^ 2 errors   someone knows java better me has tried compile files have had problems with no success. also, when run code within eclipse, ide, runs should.
any suggestions @ or solutions really, appreciated. hate thing prevents me programming. again.
edit: used able compile classes this, until started receiving error. compiling using external tool have created in eclipse ide, have tried compiling navigating directory 2 files in in cmd window , used javac nothing.java yet same error arises. have tried compiling can.java first (which compiles), , nothing.java, fails well. here text when compiling cmd window:
02/09/2011  06:44 pm    <dir>          . 02/09/2011  06:44 pm    <dir>          .. 02/09/2011  03:45 pm               289 .classpath 02/09/2011  03:45 pm               382 .project 02/09/2011  03:45 pm    <dir>          .settings 02/09/2011  06:00 pm                75 can.java 02/09/2011  05:49 pm               102 nothing.java                4 file(s)            848 bytes                3 dir(s)  64,669,216,768 bytes free  c:\users\alex\mindstorms\nxt\lejos nxj\moment>javac nothing.java nothing.java:4: cannot find symbol symbol  : class can location: class nothing                 can world = new can();                 ^ nothing.java:4: cannot find symbol symbol  : class can location: class nothing                 can world = new can();                                 ^ 2 errors      
the problem need have appropriate import statement (if in separate packages), , need run java compiler appropriate directory. supposing directory structure looks like:
src/    com/       yourdomain/          example/             can.java             nothing.java   then need following @ top of both *.java files:
package com.yourdomain.example;   and should put following import statement in nothing.java (technically not necessary when both in same package, necessary when in separate packages, , it's habit):
import com.yourdomain.example.can;   and invoke compiler within src directory follows:
 javac com/yourdomain/example/*.java   and run program using:
 java com.yourdomain.example.nothing   by way, shoudn't building projects hand way; should use automatic build system such maven or ant. if create project using netbeans ide, aside giving simple "build", "run", , "build & run" buttons plus sorts of nice ide features (code highlighting, incremental compilation , suggestions fixes), generate ant build project you.
edit
 based on updated question,... note eclipse's compiler distinct javac. if installed javac using cygwin or if you've been sharing files between windows , unix (possibly through version control system), may have run encoding issue. suggest resaving files in utf-8 , running unix2dos (or vice-versa if installed javac via cygwin) , recompiling. if doesn't work, might worth reinstalling javac. failing that, there's ubuntu ;). 
Comments
Post a Comment