• Post Reply Bookmark Topic Watch Topic
  • New Topic

Netbeans 8.0.2 problem. clicking "run" runs wrong package/mainclass  RSS feed

 
Avalon Stevens
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am a student new to learning java with using netbeans being a requirement form my course. I am trying to follow a tutorial, however I am running into an annoying problem. Clicking run on any program in my project runs the wrong class.

The set up of the project is as follows:


All .java are main classes as that is what I was told to do. The problem is no matter what I try to run, it is the TestScanner.java that is run.
code is as follows:

TestScanner



TestScanner1


TestScanner2


TestScanner3


Ex1.java


What am I missing?

 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Avalon Stevens wrote:The problem is no matter what I try to run, it is the TestScanner.java that is run.

NetBeans has a setting for that, under the project properties. There's also a context menu that allows you to run any class from the code pane.
 
Avalon Stevens
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, my code runs now.

It is strange as I did all this before I had to re-install my OS and I never saw this behaviour before.

Is having multiple main classes in a project good or bad? I read somewhere that there should only be one.
 
Stephan van Hulst
Saloon Keeper
Posts: 7972
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on your requirements. There's nothing wrong with having multiple entry points in our application. You can actually have NetBeans ask which class to run every time, or once per session, or remember your choice permanently. If you want to run a different class without changing the setting, you can right-click the class and tell NetBeans to run that file.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!