| | |
Compiling And Running
![]() |
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
I am trying to compile some java codes from a .java file that i had saved to disk. Basically i am trying to build my own ide. I have a text area in which the java code is in and also have two buttons. What i need is when i click the button the .java file on my disk is compiled and any errors are shown in the textarea
For the second button when i click it(if compilation is successfull) for the .java that has been compiled to be run.
Does anyone know how to compile and run a java program from a program?
I hope someone can help or show me some codings on how this can be achieved.
Any amount of help is greatly appreciated
Thank You
Yours Sincerely
Richard West
I am trying to compile some java codes from a .java file that i had saved to disk. Basically i am trying to build my own ide. I have a text area in which the java code is in and also have two buttons. What i need is when i click the button the .java file on my disk is compiled and any errors are shown in the textarea
For the second button when i click it(if compilation is successfull) for the .java that has been compiled to be run.
Does anyone know how to compile and run a java program from a program?
I hope someone can help or show me some codings on how this can be achieved.
Any amount of help is greatly appreciated
Thank You
Yours Sincerely
Richard West
•
•
Join Date: Dec 2004
Posts: 5
Reputation:
Solved Threads: 0
TextPad is a freely available windows program that allows you to view your source code (the .java file) in one text area. There is an option in the tools menu to compile. The output from compiling is shown is different text area. There is another option on the tools menu to run your compiled code.
Basically java is compiled via the following command:
javac filename.java
The newly compiled code will have the name filename.class. It can now be run via the following command:
java filename
Any program, like textpad, can take advantage of these two commands to run java.
Basically java is compiled via the following command:
javac filename.java
The newly compiled code will have the name filename.class. It can now be run via the following command:
java filename
Any program, like textpad, can take advantage of these two commands to run java.
•
•
•
•
Originally Posted by freesoft_2000
Hi everyone,
I am trying to compile some java codes from a .java file that i had saved to disk. Basically i am trying to build my own ide. I have a text area in which the java code is in and also have two buttons. What i need is when i click the button the .java file on my disk is compiled and any errors are shown in the textarea
For the second button when i click it(if compilation is successfull) for the .java that has been compiled to be run.
Does anyone know how to compile and run a java program from a program?
I hope someone can help or show me some codings on how this can be achieved.
Any amount of help is greatly appreciated
Thank You
Yours Sincerely
Richard West
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
hi everyone,
santa_barbarian you said
"Basically java is compiled via the following command:
javac filename.java"
let's say for example if my javac file is located in the file location
"C://abc/fd/javac.exe"
and the file i want to compile is located at "D://ac/d/lpc.java"
so when i compile the file i must writethe following on the command line
"C://abc/fd/javac D://ac/d/lpc.java"
Am i right or wrong. If i am wrong then what is the correct way to do it
Thank You
Yours Sincerely
Richard West
santa_barbarian you said
"Basically java is compiled via the following command:
javac filename.java"
let's say for example if my javac file is located in the file location
"C://abc/fd/javac.exe"
and the file i want to compile is located at "D://ac/d/lpc.java"
so when i compile the file i must writethe following on the command line
"C://abc/fd/javac D://ac/d/lpc.java"
Am i right or wrong. If i am wrong then what is the correct way to do it
Thank You
Yours Sincerely
Richard West
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
Here is what i have done so far but i always get the exception null pointer even though it is not empty but the program compiles with no errors
Here is part of the code
Am i missing something. I really do not understand why there is a null pointer exception.
I hope someone can help me with this problem
Any help is greatly appreciated
Thank You
Yours Sincerely
Richard West
Here is what i have done so far but i always get the exception null pointer even though it is not empty but the program compiles with no errors
Here is part of the code
Java Syntax (Toggle Plain Text)
public void compile () { byte[] buffer1 = new byte[2048]; int len = 0; String str9 = "C:ddk1.4/bin/javac"; String str10 = "D:gui.java"; String[] str11 = {str9, str10}; File File11 = new File("C://JIDE_Errors.TXT"); try { Runtime1 = Runtime.getRuntime(); //The below command command line is where the exception //occurs saying it is a null pointer exception Process1 = Runtime1.exec(str11); InputStream in = new BufferedInputStream(Process1.getErrorStream()); FileOutputStream out = new FileOutputStream(File11); while((len = in.read(buffer1)) != -1) { out.write(buffer1, 0, len); } Process1.waitFor(); if(Process1.exitValue() == 0) { System.out.println("Compilation Successful"); } else { } }
Am i missing something. I really do not understand why there is a null pointer exception.
I hope someone can help me with this problem
Any help is greatly appreciated
Thank You
Yours Sincerely
Richard West
NullPointerException is a RuntimeException which means you don't have to catch it in your code.
Therefore the compiler didn't complain.
Where did you get it? Figure that out and check whether whatever you're using there indeed isn't null before continuing.
If you don't know what a NullPointerException is I'd advise you to stick to simpler programs than what you're attempting to create for now.
Therefore the compiler didn't complain.
Where did you get it? Figure that out and check whether whatever you're using there indeed isn't null before continuing.
If you don't know what a NullPointerException is I'd advise you to stick to simpler programs than what you're attempting to create for now.
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
Sorry to bother you guys but what if i want to run the class file that i have already compiled.
Let's say if my compiled class is located at C:/JButtons.class
and if i want to run this class this is what i did
There is no exception thrown but the exit value of the process is 1 (meaning the program exited abnormally). I do not know what i am doing wrong. Am i running the compiled class the correct way. If not then what is the correct way of doing it. The program i trying to run has no errors when compiled.
I hope some someone can help me with this problem
Any help is greatly appreciated
Thank You
Yours Sincerely
Richard West
Sorry to bother you guys but what if i want to run the class file that i have already compiled.
Let's say if my compiled class is located at C:/JButtons.class
and if i want to run this class this is what i did
Java Syntax (Toggle Plain Text)
String[] str12 ={"C:/j2sdk1.4.2_04/bin/java", "C:/JButtons"}; Runtime Runtime1; Process Process1; try { Runtime1 = Runtime.getRuntime(); Process1 = Runtime2.exec(str12); Process1.waitFor(); } catch(Exception e) { e.printStackTrace(); }
There is no exception thrown but the exit value of the process is 1 (meaning the program exited abnormally). I do not know what i am doing wrong. Am i running the compiled class the correct way. If not then what is the correct way of doing it. The program i trying to run has no errors when compiled.
I hope some someone can help me with this problem
Any help is greatly appreciated
Thank You
Yours Sincerely
Richard West
![]() |
Similar Threads
- compiling and running issue (Java)
- Beginner problem compiling with javac (Java)
- wrong output in c program (C++)
- Need help figuring out C++ Pointers (C++)
- Notepad VS. Something Else (Java)
Other Threads in the Java Forum
- Previous Thread: CardLayout problem restated
- Next Thread: line up JTextField GUI java & write to file
| Thread Tools | Search this Thread |
6 actuate android api applet application applications array arrays automation balls bank binary bluetooth bold business c++ chat class clear client code codesnippet collections component coordinates database defaultmethod development dice doctype dragging ebook eclipse educational error file formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide ideas image infinite ingres integer intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans openjavafx parameter php problem program programming project recursion repositories scanner scrollbar sell server set sms sort sorting sql sqlserver state storm string sun superclass swing swt threads tree websites windows







