Results 1 to 20 of 21
Thread: Compile Error: Could Not Open
- 07-08-2012, 10:41 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
- 07-08-2012, 11:00 PM #2
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
Re: Compile Error: Could Not Open
I am trying to compile a package example from a textbook.
Here is the code:
// A simple package
package MyPack;
class Balance {
String name;
double bal;
Balance(String n, double b) {
name = n;
bal = b;
}
void show() {
if (bal<0)
System.out.print("--->");
System.out.println(name + " : $" + bal);
}
}
class AccountBalance {
public static void main(String args[]) {
Balance current[] = new Balance[3];
current[0] = new Balance("K. J. Fielding", 123.23);
current[1] = new Balance("Will Tell", 157.02);
current[2] = new Balance("Tom Jackson", -12.33);
for(int i = 0; i < 3; i++)
current[i].show();
}
}
The name of my file is AccountBalance.java and the directory is C:\Java\MyPack. I have my cmd directory as C:\Java and typed in java MyPack.AccountBalance and it gives me that error.
- 07-08-2012, 11:40 PM #3
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
Re: Compile Error: Could Not Open
@BiCure:
Are you sure that here 'C:\Program Files\Java\jre7\lib\amd64\jdm.cfg' is 'jdm.cfg', because I think that there should be 'jvm.cfg' file?
- 07-09-2012, 12:04 AM #4
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
Re: Compile Error: Could Not Open
You are right, the error is stating jvm not jdm, sorry for the typo.
- 07-09-2012, 12:12 AM #5
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
Re: Compile Error: Could Not Open
Is this error was in Eclipse IDE, or in Netbeans, or in something else?
Java allows several JRE/JDK to be installed at the same time, and IDE allows you to select the one to use with your project in Preferences.
- 07-09-2012, 12:18 AM #6
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
Re: Compile Error: Could Not Open
I am just using notepad.
- 07-09-2012, 12:27 AM #7
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
Re: Compile Error: Could Not Open
And trying to run in command prompt.
- 07-09-2012, 12:36 AM #8
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
Re: Compile Error: Could Not Open
If you have Windows OS you should try something like this:
My Computer -> clickRightButton -> Properties -> Advanced -> Environment Variables -> (system Variables) click on Path -> edit Path and in Path you should write this:
;C:\Program Files\Java\jre7\bin;C:\Program Files\Java\jre7\lib
and you should delete previous values in that Path that is similar to this values.
- 07-09-2012, 01:25 AM #9
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
Re: Compile Error: Could Not Open
My program folder MyPack is located in bin. Is this correct? I have my file AccountBalance.java in MyPack in the bin folder. Then when I open cmd and try to compile I get the location to the bin folder then type javac MyPack.AccountBalance.java and get an error saying file not found.
- 07-09-2012, 01:26 AM #10
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
Re: Compile Error: Could Not Open
C:\Program Files\Java\JDK\bin> javac MyPack.AccountBalance.java is how it looks in cmd
It says javac: file not found: MyPack.AcccountBalance.java
- 07-09-2012, 01:31 AM #11
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
Re: Compile Error: Could Not Open
I have gotten my program to run but the purpose of the exercise was to learn how packages work. I had to delete the package part of it to get it to run. Can you help me with how packages work? I thought I understood from my textbook but I get an error that way and can only run it when it is not part of a package.
- 07-09-2012, 01:43 AM #12
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
Re: Compile Error: Could Not Open
Using the program above, it says put AccountBalance.java in a directory called MyPack. I made a folder in bin called MyPack and saved AccountBalance.java inside
It then says, compile the file and make sure the resulting .class is also in the MyPack file. Then try executing the AccountBalance class using the following command line --> java MyPack.AccountBalance. I have C:\Program Files\Java\JDK\bin as my directory. When I have the package = MyPack; included in my program and type javac MyPack.AccountBalance.Java it will come up with an error: file not found myPack.AccountBalance.java
- 07-09-2012, 01:57 AM #13
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
Re: Compile Error: Could Not Open
^ Do not use java MyPack.AccountBalance, but use java MyPack/AccountBalance.
Do not use javac MyPack.AccountBalance.java, but use java MyPack/AccountBalance.java
I think that it should work.Last edited by cselic; 07-09-2012 at 01:59 AM.
- 07-09-2012, 02:35 AM #14
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
- 07-09-2012, 02:35 AM #15
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
Re: Compile Error: Could Not Open
With LoL in the background haha, didn't feel like edit.
- 07-09-2012, 02:43 AM #16
Senior Member
- Join Date
- Apr 2010
- Location
- Belgrade, Serbia
- Posts
- 278
- Rep Power
- 4
Re: Compile Error: Could Not Open
^Please copy + paste your error on this thread.
- 07-09-2012, 03:16 AM #17
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
Re: Compile Error: Could Not Open
Not sure how to copy paste out of cmd.
- 07-09-2012, 03:22 AM #18
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
Re: Compile Error: Could Not Open
It is in that screen capture.
- 07-09-2012, 11:28 AM #19
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: Compile Error: Could Not Open
1. Do not stick your code in the JDK folder.
You should be working in your own directory, probably in your user docs or similar.
Then you need to go through the Java tutorials at Oracle to try and get them compiling, probably the basics ones.Please do not ask for code as refusal often offends.
- 07-11-2012, 04:26 AM #20
Member
- Join Date
- Jul 2012
- Posts
- 17
- Rep Power
- 0
Re: Compile Error: Could Not Open
Well thanks for the link to get my folder straight that was easy. Also, I realized my error. After figuring out the path problems in my first endeavor and deleting the package name to get it to compile in the first place, I realized I named my package myPack instead of MyPack when I put it back in. Dumb of me. Thanks cselic and Tolls!
Similar Threads
-
Compile error :(
By Astralogic in forum New To JavaReplies: 8Last Post: 03-27-2012, 11:21 PM -
i get this error during compile
By Bibin in forum New To JavaReplies: 1Last Post: 12-24-2011, 08:43 AM -
compile error
By angryredantz in forum New To JavaReplies: 1Last Post: 01-23-2009, 10:44 PM -
Compile Error - Please Help!!
By AJ2009 in forum New To JavaReplies: 10Last Post: 01-04-2009, 03:59 PM -
compile error
By dirtycash in forum New To JavaReplies: 6Last Post: 12-12-2007, 06:00 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks