I am using JBuilder 4. When I run my program, I get an error message saying that it could not find the main method. I have the main method just underneath the first few lines of global variables. Here is the code for the first part of the app. Thanks.
Welcome to JavaRanch! An easy solution would be to move the instance variable declarations (the variables that are not static and are declared outside of any method - note that calling them global isn't really correct) into the main static method. Or you could declare that all of those variables are themselves static. Or you could do it the more object-oriented way, and from the main method, create an instance of the class and then use the methods (behavior) and variables (data, state) through that instance (so to speak) in order to do things. Getting any ideas?
Hi Nate, The error you are getting from JBuilder is probably because you have not defined your class as the one containing the main method to run. It's been a while and I don't have JBuilder on my machine at work, but I think it is under the "Project" menu and "Project Settings", or "Project Default Settings" , or something to that effect. In any case, a dialog will open with tabs along the top, I beleive the one you are looking for is "Run". Just find the tab that asks for the project main(If memory serves, it will have a pull-down list of all the classes in your project). Choose the one with the main you want to run. As for static, it means that the method or variable is defined at a CLASS LEVEL, not at an instance level, i.e. it doesn't belong to a specific INSTANCE of a class, it belongs to the CLASS itself. All instances of that class will share THE SAME static entity. This means that you do not have to instantiate an object of a class to use a static variable or method, hence the reason the main method must be static; you just call it from the command line(or ide) and it will run without having to create an object of the class you are using. I'm not a C++ coder, so I'm not sure how to relate it to that arena. Hope I haven't confused you, but try to set the project properties and see if that helps, and make sure your main method is static. Cheers, E
My theory of evolution is that Darwin was adopted. - Steven Wright