NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Could Not find or load main class (file)

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
Dsr122076



Joined: 15 Oct 2012
Posts: 4

PostPosted: Mon Oct 15, 2012 12:45 pm    Post subject: Could Not find or load main class (file) Reply with quote

Ok I am new to programming. In fact This is my second week in class. We are using Netbeans to program. I am able to get my program compiled and to run in the netbeans environment. However, when I copied the .java file to c:\java programs file folder to attempt to do the same from the command line it complies and creates the .class file. I can see both the .java and .class in the same folder.
I then try to run the program i type : java (filename without the .class portion). I get the following message: could not find or load main class (filename).

Can someone tell me what I am doing wrong?
BTW CLASSPATH is pointing to jdk1.7.0_07\bin
PATH is pointing to many files including the jdk file as well.
Back to top
Bayless Kirtley
Posted via mailing list.





PostPosted: Mon Oct 15, 2012 2:43 pm    Post subject: Could Not find or load main class (file) Reply with quote

The jar file specifies the original path to its main class. By moving to
another location, it has been changed.


-----Original Message-----
From: Dsr122076
Sent: Monday, October 15, 2012 7:45 AM
To: address-removed
Subject: [nbusers] Could Not find or load main class (file)

Ok I am new to programming. In fact This is my second week in class. We are
using Netbeans to program. I am able to get my program compiled and to run
in the netbeans environment. However, when I copied the .java file to
c:\java programs file folder to attempt to do the same from the command line
it complies and creates the .class file. I can see both the .java and .class
in the same folder.
I then try to run the program i type : java (filename without the .class
portion). I get the following message: could not find or load main class
(filename).

Can someone tell me what I am doing wrong?
BTW CLASSPATH is pointing to jdk1.7.0_07\bin
PATH is pointing to many files including the jdk file as well.






-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.2740 / Virus Database: 2601/5831 - Release Date: 10/14/12
Back to top
Dsr122076



Joined: 15 Oct 2012
Posts: 4

PostPosted: Mon Oct 15, 2012 2:53 pm    Post subject: Re: Could Not find or load main class (file) Reply with quote

Bayless Kirtley wrote:
The jar file specifies the original path to its main class. By moving to
another location, it has been changed.


-----Original Message-----
From: Dsr122076
Sent: Monday, October 15, 2012 7:45 AM
To: address-removed
Subject: [nbusers] Could Not find or load main class (file)

Ok I am new to programming. In fact This is my second week in class. We are
using Netbeans to program. I am able to get my program compiled and to run
in the netbeans environment. However, when I copied the .java file to
c:\java programs file folder to attempt to do the same from the command line
it complies and creates the .class file. I can see both the .java and .class
in the same folder.
I then try to run the program i type : java (filename without the .class
portion). I get the following message: could not find or load main class
(filename).

Can someone tell me what I am doing wrong?
BTW CLASSPATH is pointing to jdk1.7.0_07\bin
PATH is pointing to many files including the jdk file as well.






-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.2740 / Virus Database: 2601/5831 - Release Date: 10/14/12


.jar file? I made the file .java in netbeans. I then copied it to c:\java programs . I then used the javac command to compile and it created the .class file. But I still cannot run the class file from thecommand prompt.

Are you telling me that I need to copy the program into notepad then rename it .java and compile it?
Back to top
Dsr122076



Joined: 15 Oct 2012
Posts: 4

PostPosted: Mon Oct 15, 2012 3:01 pm    Post subject: Re: Could Not find or load main class (file) Reply with quote

Dsr122076 wrote:
Bayless Kirtley wrote:
The jar file specifies the original path to its main class. By moving to
another location, it has been changed.


-----Original Message-----
From: Dsr122076
Sent: Monday, October 15, 2012 7:45 AM
To: address-removed
Subject: [nbusers] Could Not find or load main class (file)

Ok I am new to programming. In fact This is my second week in class. We are
using Netbeans to program. I am able to get my program compiled and to run
in the netbeans environment. However, when I copied the .java file to
c:\java programs file folder to attempt to do the same from the command line
it complies and creates the .class file. I can see both the .java and .class
in the same folder.
I then try to run the program i type : java (filename without the .class
portion). I get the following message: could not find or load main class
(filename).

Can someone tell me what I am doing wrong?
BTW CLASSPATH is pointing to jdk1.7.0_07\bin
PATH is pointing to many files including the jdk file as well.






-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.2740 / Virus Database: 2601/5831 - Release Date: 10/14/12


.jar file? I made the file .java in netbeans. I then copied it to c:\java programs . I then used the javac command to compile and it created the .class file. But I still cannot run the class file from thecommand prompt.

Are you telling me that I need to copy the program into notepad then rename it .java and compile it?


Ok just tried that same problem occurs even when typed in to notepad and saved with .java extension. It creates .class but cannot execute the file.
Back to top
Dsr122076



Joined: 15 Oct 2012
Posts: 4

PostPosted: Mon Oct 15, 2012 3:57 pm    Post subject: Ok I figured it out Reply with quote

I cannot just type java (file name) in the command prompt. I have to type the following:

java -jar "C:\*\*\*\NetBeansProjects\WindowTest\dist\WindowTest.jar"


----* = full path to file

I guess this runs the .jar file that was previously mentioned. I just did not know that existed. So I followed the entire path. and then it worked...... Silly me figured out later that if we read the bottom of the screen when we succesfully create the program it tells us what to type to run it from a command promt.

To run this application from the command line without Ant, try:
java -jar "C:\*\*\*\NetBeansProjects\WindowTest\dist\WindowTest.jar"
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo