NetBeans Forums

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

main class problem

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



Joined: 12 Feb 2009
Posts: 31

PostPosted: Mon Mar 15, 2010 5:41 pm    Post subject: main class problem Reply with quote

Hi all,
in my NetBeans 8.6, i choosed :
File menu > New Project
Categories : Java
Projects : Java Application
next
i fill the Project Name and CHECK the "create Mail class" CheckBox
Finish

i write a simple code like this :
Code:
package mypckg;

import javax.swing.*;
import java.awt.*;

public class Main   {
  static JFrame theJFrame;
  static Container c;
  public static void main(String[] args) {
  theJFrame = new JFrame("JFrame Title");
    theJFrame.setSize(200,200);
    c = theJFrame.getContentPane();
                                                        }
                           }


BUT : When i try to run the code i get the message :
mypckg.Main class was not found in trydist1 project
<No main classes found>

Any one tell me what is the problem? and are there conditions for a class to be a main class??
Many Thanks
Back to top
Javier.Ortiz
Posted via mailing list.





PostPosted: Mon Mar 15, 2010 5:48 pm    Post subject: main class problem Reply with quote

Right click the project>Properties>Run

Select the main class from there. I thought that checking the create main class did this automatically...

Javier A. Ortiz Bultr
Back to top
ellias2007



Joined: 12 Feb 2009
Posts: 31

PostPosted: Mon Mar 15, 2010 6:00 pm    Post subject: Reply with quote

Thanks for your quick reply,
when i went to properties>Run, i found already in the field "Main class" : mypckg.Main...
and also when i click the Browse button at right, i get in the "Browse Main classes" window :
Main classes : <No main classes found>
... it is really ubnormal!
Back to top
Javier.Ortiz
Posted via mailing list.





PostPosted: Mon Mar 15, 2010 7:18 pm    Post subject: main class problem Reply with quote

At least on daily build ot works fine.

Make sure there's a line main.class in nbproject/project.properties.

Javier A. Ortiz Bultr
Back to top
ellias2007



Joined: 12 Feb 2009
Posts: 31

PostPosted: Mon Mar 15, 2010 8:02 pm    Post subject: Re: main class problem Reply with quote

Quote:
Make sure there's a line main.class in nbproject/project.properties.


YES, this line exists (main.class=mypckg.Main)
also, there is a manifest file in witch i found written :
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

Thanks for any help
Back to top
etech



Joined: 18 Mar 2010
Posts: 1

PostPosted: Thu Mar 18, 2010 5:04 am    Post subject: Reply with quote

Hi,

I am having this same problem. It seems that the constructor method must be static, otherwise the main class ceases to be the main class after saving.

For instance, having the constructor for class NewMain as:

Code:
public static void main(String[] args) {
}


..keeps the class as the main class. Whereas, changing the method to:

Code:
public void main(String[] args){
}


..causes the class to become a non-main class after saving.


Is this a bug?


etech



Product Version: NetBeans IDE 6.8 (Build 200912041610)
Java: 1.6.0_18; Java HotSpot(TM) Client VM 16.0-b13
System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)
Back to top
Bayless Kirtley
Posted via mailing list.





PostPosted: Thu Mar 18, 2010 1:53 pm    Post subject: main class problem Reply with quote

Not a bug but a Java requirement. After you make that change, it is not even
a proper main method.


----- Original Message -----
From: "etech" <address-removed>
To: <address-removed>
Sent: Thursday, March 18, 2010 12:04 AM
Subject: [nbusers] main class problem


Quote:
Hi,

I am having this same problem. It seems that the constructor method must
be static, otherwise the main class ceases to be the main class after
saving.

For instance, having the constructor for class NewMain as:


Code:
public static void main(String[] args) {
}



..keeps the class as the main class. Whereas, changing the method to:


Code:
public void main(String[] args){
}



..causes the class to become a non-main class after saving.


Is this a bug?


etech



Product Version: NetBeans IDE 6.8 (Build 200912041610)
Java: 1.6.0_18; Java HotSpot(TM) Client VM 16.0-b13
System: Windows XP version 5.1 running on x86; Cp1252; en_US (nb)



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