Where to put main method ?

I am working on a small factorial problem and keep recieving Exeption in thread "main" java.lang.NoSuchMethod: main error
I know my class is missing the public static void main(String[] args) method but since i am used to using Blue J and have now moved to SDK im not sure how to implement the main method into my current program
I would appreciate any help, current program is :
public class Factorial
private int total;
private int temp;
private int counter;
public Factorial(int factor)
counter = factor;
total = factor;
Calculation();
public void Calculation()
if(counter > 1){
temp = counter - 1;
total = (total * temp);
counter = temp;
Calculation();
else{
System.out.println(total);
}

Sorry i should have explained a little better
i have to create to new programs, one iterative and one recursive for calculating : fac(n) = n * (n -1) * (n-2) * (n-3) ... till n = 1
the program does its job properly when run in Blue J (the whole reason for this stupid programme is to practice using SDK instead of Blue J funny enough)
im still working through it and hope to solve it on my own (for the sake of pride more than anything ) but i have a limit and im really struggling with using this new main method .
Really appreciatte any help and thanks for it so far

Similar Messages

  • Why dont to put construcor in a main() method

    Hi,
    public class checkNumeric
         public static void main(String a[])
              public checkNumeric(){
                   System.out.println("I am in Constructor:::");
              checkNumeric ob=new checkNumeric();
    Can u plz tell y dont put cnstructor in main() method.

    Do you know what a constructor is? Can you put one method inside another method?

  • Where to put java code - Best Practice

    Hello. I am working with the Jdeveloper 11.2.2. I am trying to figure out the best practice for where to put code. After reviewing http://docs.oracle.com/cd/E26098_01/web.1112/e16182.pdf it seemed like the application module was the preferred spot (although many of the examples in the pdf are in main methods). After coding a while though, I noticed that there were quite a few libraries imported, and wondered whether this would impact performance.
    I reviewed postings on the forum, especially Re: Access service method (client interface) programmatically . This link mentions accessing code from a backing bean -- and the gist of the recommendations seems to be to use the data control to drag it to the JSF, or use the bindings to access code.
    My interest lies in where to put java code in the first place; In the View Object, Entity Object, and Am object, backing bean.....other?
    I can outline several best guesses about where to put code and the pros and cons:
    1. In the application module
    Pros: Centralized location for code makes development and support more simple as there are not multiple access points. Much like a data control centralizes services, the application module can act as a conduit for different pieces of code you have in objects in your model.
    Cons: Everything in one place means the application module becomes bloated. I am not sure how memory works in java -- if the app module has tons of different libraries are they all called when even a simple query re-execute method is called? Memory hog?
    2. Write code in the objects it affects. If you are writing code that accesses a view object, write it in a view object. Then make it visible to the client.
    pros: The code is accessed via fewer conduits (for example, I would expect that if you call the application module from a JSF backing bean, then the application module calls the view object, you have three different pieces of code --
    conts: The code gets spread out, harder to locate etc.
    I would greatly appreciate your thoughts on the matter.
    Regards,
    Stuart
    Edited by: Stuart Fleming on May 20, 2012 5:25 AM
    Edited by: Stuart Fleming on May 20, 2012 5:27 AM

    First point here is when you say "where to put the java code" and you're referring to ADF BC, the point is you put "business logic java code" in the ADF Business Components. It's fine of course to have Java code in the ViewController layer that deals with the UI layer. Just don't put business logic in the UI layer, and don't put UI logic in the model layer. In your 2 examples you seem to be considering the ADF BC layer only, so I'll assume you mean business logic java code only.
    Meanwhile I'm not keen on the term best practice as people follow best practices without thinking, typically best practices come with conditions and people forget to apply them. Luckily you're not doing that here as you've thought through the pros and cons of each (nice work).
    Anyway, back on topic and off my soap box, as for where to put your code, my thoughts:
    1) If you only have 1 or 2 methods put it in the AppModuleImpl
    2) If you have hundreds of methods, or there's a chance #1 above will morph into #2, split the code up between the AppModuleImpl, ViewImpl and ViewRowImpls. Why? Because your AM will become overloaded with hundreds of methods making it unreadable. Instead put the code where it should logically go. Methods that work on a specific VO row go into the associated ViewRowImpl, methods that work across rows in a VO go into the ViewImpl, and methods that work across VOs in the associated AppModuleImpl.
    To be honest which you ever option you choose, one thing I do recommend as a best practice is be consistent and document the standard so your other programmers know.
    Btw there isn't an issue about loading lots of libraries/imports into a class, it has no runtime cost. However if your methods require lots of class variables, then yes this will have a memory cost.
    On a side note if you're interested in more ideas around how to build ADF apps correctly think about joining the "ADF EMG", a free online forum which discusses ADF architecture, best practices (cough), deployment architectures and more.
    Regards,
    CM.

  • Architecture question...where to put the code

    Newbie here, so please be gentle and explicit (no detail is
    too much to give or insulting to me).
    I'm hoping one of you architecture/design gurus can help me
    with this. I am trying to use good principals of design and not
    have code scattered all over the place and also use OO as much as
    possible. Therefore I would appreciate very much some advice on
    best practices/good design for the following situation.
    On my main timeline I have a frame where I instantiate all my
    objects. These objects refer to movieClips and textFields etc. that
    are on a content frame on that timeline. I have all the
    instantiation code in a function called initialize() which I call
    from the content frame. All this works just fine. One of the
    objects on the content frame is a movieClip which I allow the user
    to go forward and backward in using some navigation controls.
    Again, the object that manages all that is instantiated on the main
    timeline in the initialize() function and works fine too. So here's
    my question. I would like to add some interactive objects on some
    of the frames of the movieClip I allow the user to navigate forward
    and backward in (lets call it NavClip) . For example on frame 1 I
    might have a button, on frame 2 and 3 nothing, on frame 4 maybe a
    clip I allow the user to drag around etc. So I thought I would add
    a layer to NavClip where I will have key frames and put the various
    interactive assets on the appropriate key frames. So now I don't
    know where to put the code that instantiates these objects (i.e.
    the objects that know how to deal with the events and such for each
    of these interactive assets). I tried putting the code on my main
    timeline, but realized that I can't address the interactive assets
    until the NavClip is on the frame that holds the particular asset.
    I'm trying not to sprinkle code all over the place, so what do I
    do? I thought I might be able to address the assets by just
    providing a name for the asset and not a reference to the asset
    itself, and then address the asset that way (i.e.
    NavClip["interactive_mc"] instead of NavClip.interactive_mc), but
    then I thought that's not good since I think there is no type
    checking when you use the NavClip["interactive_mc"] form.
    I hope I'm not being too dim a bulb on this and have missed
    something really obvious. Thanks in advance to anyone who can help
    me use a best practice.

    1. First of all, the code should be:
    var myDraggable:Draggable=new Draggable(myClip_mc);
    myDraggable.initDrag();
    Where initDrag() is defined in the Draggable class. When you
    start coding functions on the timeline... that's asking for
    problems.
    >>Do I wind up with another object each time this
    function is called
    Well, no, but. That would totally depend on the code in the
    (Draggable) class. Let's say you would have a private static var
    counter (private static, so a class property instead of an instance
    property) and you would increment that counter using a
    setInterval(). The second time you enter the frame and create a new
    Draggable object... the counter starts at the last value of the
    'old' object. So, you don't get another object with your function
    literal but you still end up with a faulty program. And the same
    goes for listener objects that are not removed, tweens that are
    running and so on.
    The destroy() method in a custom class (=object, I can't
    stress that enough...) needs to do the cleanup, removing anything
    you don't need anymore.
    2. if myDraggable != undefined
    You shouldn't be using that, period. If you don't need the
    asset anymore, delete it using the destroy() method. Again, if you
    want to make sure only one instance of a custom object is alive,
    use the Singleton design pattern. To elaborate on inheritance:
    define the Draggable class (class Draggable extends MovieClip) and
    connect it to the myClip_mc using the linkage identifier in the
    library). In the Draggable class you can define a function unOnLoad
    (an event fired when myClip_mc is removed using
    myClip_mc.removeMovieClip()...) and do the cleanup there.
    3. A destroy() method performs a cleanup of any assets we
    don't need anymore to make sure we don't end up with all kinds of
    stuff hanging around in the memory. When you extend the MovieClip
    Class you can (additionally) use the onUnLoad event. And with the
    code you posted, no it wouldn't delete the myClip_mc unless you
    program it to do so.

  • Where to put removeChild (Away3d 4.x)

    Hey guys i need some help on how to change primitives and removing the previous primitive showing in the scene and also changing materials on the primitive with a click of a button.
    Mainly just where to put removeChild.
    This is for Away3d
    package
        import away3d.cameras.*;
        import away3d.containers.*;
        import away3d.controllers.*;
        import away3d.core.base.SubGeometry;
        import away3d.core.base.data.Vertex;
        import away3d.debug.*;
        import away3d.entities.Mesh;
        import away3d.extrusions.*;
        import away3d.filters.*;
        import away3d.lights.*;
        import away3d.materials.*;
        import away3d.materials.lightpickers.*;
        import away3d.materials.methods.*;
        import away3d.primitives.*;
        import away3d.textures.*;
        import away3dplus.controllers.SimpleHoverController;
        import flash.display.Bitmap;
        import flash.display.BitmapData;
        import flash.display.Sprite;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.geom.Vector3D;
        import flash.text.TextField;
        import flash.text.TextFieldAutoSize;
        import flash.text.TextFormat;
        [SWF(backgroundColor="#000000",frameRate="30",quality="LOW")]
        public class Main extends Sprite
        //engine variables
        private var view:View3D;
        private var scene:Scene3D;
        // debug
        private var awayStats:AwayStats;
        //light objects
        private var pointLight:PointLight;
        private var lightPicker:StaticLightPicker;
        //material objects
        private var redColorMaterial:ColorMaterial;
        private var skyBoxCubeTexture:BitmapCubeTexture;
        //Buttons   
        private var btnCube:Sprite = new Sprite
        private var btnSphere:Sprite = new Sprite
        private var btnCylinder:Sprite = new Sprite
        private var btnTorus:Sprite = new Sprite   
        private var btnMaterial:Sprite = new Sprite   
        private var btnWireframe:Sprite = new Sprite
            public function Main() {
                init();
                private function init():void {
                    initEngine();
                    initLights();
                    initCamera();
                    initMaterials();
                    initObjects();
                    initListeners();
                    drawButton()
                    btnCube.addEventListener(MouseEvent.CLICK, changeCube);
                    btnCube.x = 400;
                    btnCube.y = 25;
                    addChild(btnCube);
                    btnSphere.addEventListener(MouseEvent.CLICK, changeSphere);
                    btnSphere.x = 400;
                    btnSphere.y = 60;
                    addChild(btnSphere);
                    btnCylinder.addEventListener(MouseEvent.CLICK, changeCylinder);
                    btnCylinder.x = 400;
                    btnCylinder.y = 95;
                    addChild(btnCylinder);
                    btnTorus.addEventListener(MouseEvent.CLICK, changeTorus);
                    btnTorus.x = 400;
                    btnTorus.y = 130;
                    addChild(btnTorus);
                    //btnMaterial.addEventListener(MouseEvent.CLICK, changeMaterial);
                    btnMaterial.x = 15;
                    btnMaterial.y = 95;
                    addChild(btnMaterial);
                    btnWireframe.addEventListener(MouseEvent.CLICK, changeWireframe);
                    btnWireframe.x = 15;
                    btnWireframe.y = 130;
                    addChild(btnWireframe);
                 * Initialise the engine
                private function initEngine():void {
                    //stage setup
                    stage.scaleMode = StageScaleMode.NO_SCALE;
                    stage.align = StageAlign.TOP_LEFT;
                    // 3d view - window into 3d scene
                    view = new View3D();
                    addChild(view);
                    // 3d scene.
                    scene = view.scene;
                    // stats
                    awayStats = new AwayStats(view);
                    addChild(awayStats);
                 * Initialise the lights
                private function initLights():void {
                    //point light
                    pointLight = new PointLight();
                    scene.addChild(pointLight);
                    lightPicker = new StaticLightPicker([pointLight]);
                private function initCamera():void {
                    var hoverCameraManager:SimpleHoverController = new SimpleHoverController(view, 700, [pointLight]);
                 * Initialise Buttons
                private function drawButton():void {
                    var textLabel:TextField = new TextField()
                    btnCube.graphics.clear();
                    btnCube.graphics.beginFill(0xFFFFFF); // white
                    btnCube.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH
                    textLabel.text = "CUBE";
                    textLabel.x = 22;
                    textLabel.y = 4;
                    textLabel.selectable = false;
                    btnCube.addChild(textLabel)
                var textLabel01:TextField = new TextField()   
                btnSphere.graphics.clear();
                btnSphere.graphics.beginFill(0xFFFFFF); // white
                btnSphere.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH   
                textLabel01.text = "SPHERE";
                textLabel01.x = 18;
                textLabel01.y = 3;
                textLabel01.selectable = false;
                btnSphere.addChild(textLabel01)
                var textLabel03:TextField = new TextField()   
                btnCylinder.graphics.clear();
                btnCylinder.graphics.beginFill(0xFFFFFF); // white
                btnCylinder.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH   
                textLabel03.text = "CYLINDER";
                textLabel03.x = 10;
                textLabel03.y = 3;
                textLabel03.selectable = false;
                btnCylinder.addChild(textLabel03)   
                var textLabel04:TextField = new TextField()   
                btnTorus.graphics.clear();
                btnTorus.graphics.beginFill(0xFFFFFF); // white
                btnTorus.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH   
                textLabel04.text = "TORUS";
                textLabel04.x = 17;
                textLabel04.y = 3;
                textLabel04.selectable = false;
                btnTorus.addChild(textLabel04)   
                var textLabel05:TextField = new TextField()   
                btnMaterial.graphics.clear();
                btnMaterial.graphics.beginFill(0xFFFFFF); // white
                btnMaterial.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH   
                textLabel05.text = "MATERIAL";
                textLabel05.x = 6;
                textLabel05.y = 3;
                textLabel05.selectable = false;
                btnMaterial.addChild(textLabel05)       
                var textLabel06:TextField = new TextField()   
                btnWireframe.graphics.clear();
                btnWireframe.graphics.beginFill(0xFFFFFF); // white
                btnWireframe.graphics.drawRoundRect(0, 0, 80, 25, 10, 10); // x, y, width, height, ellipseW, ellipseH   
                textLabel06.text = "WIREFRAME";
                textLabel06.x = 2;
                textLabel06.y = 3;
                textLabel06.selectable = false;
                btnWireframe.addChild(textLabel06)       
                 * Initialise the materials
                private function initMaterials():void {
                    // red color
                    redColorMaterial = new ColorMaterial(0xFF0000, 0.8);
                    redColorMaterial.lightPicker = lightPicker;
                    skyBoxCubeTexture = new BitmapCubeTexture(new EnvPosX().bitmapData, new EnvNegX().bitmapData, new EnvPosY().bitmapData, new EnvNegY().bitmapData, new EnvPosZ().bitmapData, new EnvNegZ().bitmapData);
                 * Initialise the scene objects
                private function initObjects():void {
                    var trident:Trident = new Trident(100);
                    trident.x = 0;
                    trident.y = 0;
                    scene.addChild(trident);
                    //Geometry - Geometry is a collection of SubGeometries, each of which contain the actual geometrical data such as vertices, normals, uvs, etc.
                        ////PrimitiveBase    - PrimitiveBase is an abstract base class for mesh primitives, which are prebuilt simple meshes.
                            //CubeGeometry     A Cube primitive mesh.
                            var newCubeGeometry:CubeGeometry = new CubeGeometry(200, 200, 200, 50, 50, 50, true);
                            //SphereGeometry - A UV Sphere primitive mesh.
                            var newSphereGeometry:SphereGeometry = new SphereGeometry(50, 16, 12, true);
                            //CapsuleGeometry     A UV Capsule primitive mesh.
                            var newCapsuleGeometry:CapsuleGeometry = new CapsuleGeometry(50, 100, 16, 12, true);
                            //ConeGeometry     A UV Cone primitive mesh.
                            //var newConeGeometry:ConeGeometry = new ConeGeometry(50, 100, 16, 1, true, true);
                            //CylinderGeometry     A UV Cylinder primitive mesh.
                            var newCylinderGeometry:CylinderGeometry = new CylinderGeometry(50, 50, 100, 16, 1, true, true);
                            //PlaneGeometry     A Plane primitive mesh.
                            var newPlaneGeometry:PlaneGeometry = new PlaneGeometry(100, 100, 1, 1, true);
                            //RegularPolygonGeometry     A UV RegularPolygon primitive mesh.
                            var newRegularPoligonGeometry:RegularPolygonGeometry = new RegularPolygonGeometry(100, 16, true);
                            //TorusGeometry     A UV Torus primitive mesh.
                            var newTorusGeomentry:TorusGeometry = new TorusGeometry(50, 50, 15, 8, true);
                    // Entity - The Entity class provides an abstract base class for all scene graph objects that are considered having a "presence" in the scene,
                    //            in the sense that it can be considered an actual object with a position and a size (even if infinite or idealised), rather than a grouping.
                        //Mesh - Mesh agregates instance of a Geometry, augmenting it with a presence in the scene graph, a material, and an animations tate.
                        //            It consists out of SubMeshes, which in turn correspond to SubGeometries. SubMeshes allow different parts of the geometry to be assigned different materials.
                        //var cube:Mesh = new Mesh(newCubeGeometry, redColorMaterial);
                        //cube.x = 100;
                        //cube.y = 100;   
                        //cube.z = 100;
                        //scene.addChild(cube);
                        //var sphere:Mesh = new Mesh(newSphereGeometry, redColorMaterial);
                        //sphere.x = -75;
                        //sphere.y = -150;
                        //scene.addChild(sphere);
                        //var capsule:Mesh = new Mesh(newCapsuleGeometry, redColorMaterial);
                        //capsule.x = -200;
                        //capsule.y = -150
                        //scene.addChild(capsule);
                        //var cone:Mesh = new Mesh(newConeGeometry, redColorMaterial);
                        //cone.x = -200;
                        //cone.y = 150;
                        //cone.showBounds = true;
                        //scene.addChild(cone);
                        //var cylinder:Mesh = new Mesh(newCylinderGeometry, redColorMaterial);
                        //cylinder.x = -75;
                        //cylinder.y = 150;
                        //scene.addChild(cylinder);
                        //var plane:Mesh = new Mesh(newPlaneGeometry, redColorMaterial);
                        //plane.x = -75;
                        //plane.y = 275;
                        //scene.addChild(plane);
                        //var poligon:Mesh = new Mesh(newRegularPoligonGeometry, redColorMaterial);
                        //poligon.x = -275;
                        //poligon.y = 275;
                        //scene.addChild(poligon);
                        //var torus:Mesh = new Mesh(newTorusGeomentry, redColorMaterial);
                        //torus.x = -275;           
                        //scene.addChild(torus);
                        //SkyBox     A SkyBox class is used to render a sky in the scene.
                        //var skyBox:SkyBox = new SkyBox(skyBoxCubeTexture);
                        //scene.addChild(skyBox);
                        // SegmentSet
                            //WireframeAxesGrid - Class WireframeAxesGrid generates a grid of lines on a given planeWireframeAxesGrid
                            //var wireFrameAxesGrid:WireframeAxesGrid = new WireframeAxesGrid(4, 400, 1);
                            //scene.addChild(wireFrameAxesGrid);
                            //WireframeGrid     Class WireframeGrid generates a grid of lines on a given planeWireframeGrid
                            //var wireframeGrid:WireframeGrid = new WireframeGrid(10, 100, 5, 0x0000FF);
                            //wireframeGrid.x = 75;
                            //wireframeGrid.y = 275;
                            //scene.addChild(wireframeGrid);
                            //WireframePrimitiveBase
                                //WireframeCube    - Class WireFrameGrid generates a grid of lines on a given planeWireFrameGrid
                                //var wireFrameCube:WireframeCube = new WireframeCube(100, 100, 100, 0x0000FF, 5);
                                //wireFrameCube.x = 75;
                                //scene.addChild(wireFrameCube);
                                //WireframeSphere - Class WireFrameGrid generates a grid of lines on a given planeWireFrameGrid
                                //var wireFrameSphere:WireframeSphere = new WireframeSphere(50, 16, 12, 0x0000FF, 5);
                                //wireFrameSphere.x = 75;
                                //wireFrameSphere.y = -150;
                                //scene.addChild(wireFrameSphere);
                                //WireframePlane
                                //var wireframePlane:WireframePlane = new WireframePlane(100, 100, 10, 10, 0x0000FF, 5);
                                //wireframePlane.x = 175;
                                //wireframePlane.y = 275;
                                //scene.addChild(wireframePlane);
                 * Initialise the listeners
                private function initListeners():void {
                    addEventListener(Event.ENTER_FRAME, onEnterFrame);
                 * render loop
                private function onEnterFrame(event:Event):void {
                    view.render();
                 * Intialise the buttons events
                private function changeCube(event:MouseEvent):void {
                    var newCubeGeometry:CubeGeometry = new CubeGeometry(200, 200, 200, 50, 50, 50, true);
                    var cube:Mesh = new Mesh(newCubeGeometry, redColorMaterial);
                    cube.x = 100;
                    cube.y = 100;   
                    cube.z = 100;
                    scene.addChild(cube);
                    private function changeSphere(event:MouseEvent):void {   
                         var newSphereGeometry:SphereGeometry = new SphereGeometry(50, 16, 12, true);
                         var sphere:Mesh = new Mesh(newSphereGeometry, redColorMaterial);
                         scene.addChild(sphere);
                    private function changeCylinder(event:MouseEvent):void {   
                        var newCylinderGeometry:CylinderGeometry = new CylinderGeometry(50, 50, 100, 16, 1, true, true);
                        var cylinder:Mesh = new Mesh(newCylinderGeometry, redColorMaterial);
                        scene.addChild(cylinder);
                    private function changeTorus(event:MouseEvent):void {   
                        var newTorusGeomentry:TorusGeometry = new TorusGeometry(50, 50, 15, 8, true);
                        var torus:Mesh = new Mesh(newTorusGeomentry, redColorMaterial);
                        scene.addChild(torus);
                    private function changeWireframe(event:MouseEvent):void {   
                        var wireFrameCube:WireframeCube = new WireframeCube(100, 100, 100, 0x0000FF, 5);
                        scene.addChild(wireFrameCube);
    Thanks, Matthew

    Fraudulent seller.
    I received an empty package.- - 
    Back to the drawing board.
    Thanks for your replies.
    eBay is going through their required steps.
    It will take a week or better to get my refund.
    Thanks
    Shopping for another "Mac Pro Late 2013" or I might settle for my "Mac Mini 2012 i7 16 Gig 256 SSD Intel 4000" refurb with warranty bought from Apple that I already have on hand.
    Thank You
    I don't know how this ended upon two threads.
    I'm pretty sure I'm going to go with my 2012 Mac Mini i7 16 gig 256 SSD and Lacie Little Big Thunderbolt 1 512 SSD
    That will be pretty punchy for me.
    I'll only have about $1,000 in the computer itself with a three year Apple Care Warranty.
    It should sell for $500 a year from now if I choose too.
    I think it's going to work great.
    I'm going to load it up with all of the software just like I was going to do on the Mac Pro.
    It's good for three computers in the future so no money lost on the software
    I'll probably just keep the Mini indefinitely for a backup even after I upgrade to the newer 2015 Mac Pro later next year.
    Thanks

  • Static main methods and run()

    I am having trouble with main methods, and how to structure code, im not 100% sure on what static methods are, and im not sure how to use it when calling other methods etc cos its static and stuff - i read that i should put stuff in the constructor - but im not sure how this will work with a run()
    I have written a program to draw some objects (just an oval at a certain position)
    anyway here is the main method:
    public static void main(String[] args) {
            // TODO code application logic here
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    Main game = new Main();
                    game.createAndShowGUI();
                    //Create some graphics objects at the desired position!
                    GOA[0] = new GraphicsObject(300,200);         *
                    GOA[1] = new GraphicsObject(350,200);         *
                    game.frame.updateGraphics(GOA);            *
        }I am getting "non-static variable GOA cannot be referenced from a static context" at * i cant just make everything static, how should this be structured? where should the run() be?
    Thanks for any help

    Ok, i might as well include the whole thing - its not too big , and i would like to see if any of it is right really.
    ackage joefootball2;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferStrategy;
    public class Main {
        GameWindow frame;
        //Create the graphics object array to pass to the painting stuff
        GraphicsObject[] GOA;
        private void createAndShowGUI() {
            //Create and set up the window.
            frame = new GameWindow();
            frame.DrawWindow();
        public static void main(String[] args) {
            // TODO code application logic here
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    Main game = new Main();
                    game.createAndShowGUI();
                    //Create some graphics objects!
                    GOA[0] = new GraphicsObject(300,200);
                    GOA[1] = new GraphicsObject(350,200);
                    game.frame.updateGraphics(GOA);
    class GameWindow extends JFrame
        DrawPanel canvas;
        public void updateGraphics(GraphicsObject[] GOA)
            canvas.updateObjects(GOA);
        public void DrawWindow()
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            canvas = new DrawPanel();
            canvas.setDoubleBuffered(true);
            this.getContentPane().add(canvas);
            this.setVisible(true);
            this.setSize(800, 600);
            this.setResizable(false);
    class DrawPanel extends JPanel
        //Create the graphics object array to draw
        GraphicsObject[] GOA;
        public void updateObjects(GraphicsObject[] givenGOA)
            GOA=givenGOA;
        public void paint(Graphics g)
            for (int i=0 ; i<GOA.length ; i++)
                g.drawOval(GOA.x-5, GOA[i].x-5, 10, 10);
    class GraphicsObject
    //for now, just make the graphics object a point to draw a circle
    int x; int y;
    }thanks                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Main method errors

    I am trying to create the Euclid Algorithm in a simple command line application. I get the following error when I try to compile...
    Cannot make a static reference to the non-static method getInputs()
    Cannot make a static reference to the non-static method doGCD()
    Cannot make a static reference to the non-static method doLCM()
    public class Euclid
         public static void main(String[] args)
    //This is where I try to invoke the methods getInputs(), doGCD(), and doLCM() but it errors.
         public void getInputs()
         {      //User defined inputs
         public void doGCD()     
         {      //Algorithm
         public void doLCM()     
         {      //Algorithm               
    Is there a proper way to invoke these because I've been researching and I think I need to create objects, but I'm not sure what that means.

    adam.lee wrote:
    Try putting your methods outside of the main method. What does that even mean? They are outside the main() method. Unless you mean call them somewhere else, but that doesn't make sense because if you can't call any methods inside the main() method then you can't make your program do anything.
    You can call them inside the main method but you might have to put 'static' in front.Terrible advice. You only ever make a method static if it needs to be static. Never, ever, ever, ever, EVER make a method static just for the sake of getting your program to compile. This breeds ignorance of what the term 'static' even means. Only make it static if it should belong to the class, and not an object of the class. A method like getInputs() shouldn't be static because each Euclid object could potentially have it's own inputs.

  • Where to put .txt file with SimpleInput

    Hello everyone,
    I'm rather new to Java and have a slight problem. The thing is that I need to write an app that can read a text file in this format:
    2
    Orc
    name = Gnorck
    experience = 20
    maxHealthPoints = 50
    healthPoints = 30
    maxBerserk = 9
    berserk = 7
    Human
    name = Aragorn
    experience = 45
    maxHealthPoints = 40
    healthPoints = 30
    maxGreed = 20
    greed = 10
    The first number is de number of characters in the file and after that every character is described in 7 lines.
    Now the application has to be able to read the file. I've choosen to first just make a list of characters. A friend helped me with this code but I'm not completely sure if I know how it works. The code:
    package RPGApplicatie;
    import java.util.*;
    public class Karakters {
         //Constructor
         public Karakters(int size){
              karakters = new ArrayList(size);
         //Methode voor het toevoegen van een karakter
         public void voegToe(Karakter k){
              karakters.add(k);
         public static Karakters readFile(String filename) throws ClassNotFoundException, RuntimeException, InstantiationException, IllegalAccessException{
              SimpleInput file = new SimpleInput(filename);
              int size = file.nextInt();
              Karakters result = new Karakters(size);
              for(int i = 0; i < size ; i++) {
                   Class c = Class.forName(file.nextLine());
                   result.voegToe((Karakter)c.newInstance());
              return result;
         //Variabelen aanmaken
         private ArrayList<Karakter> karakters;
    }First question: I have the classes Karakter (which is the superclass for class Human and Orc), Human and Orc. So does the method forName scan for strings that are also classes? Like so it scans the file and when it comes across a line that says either 'Orc' or 'Human' it adds it to the list?
    Second question: Where to put the text file that holds the data? I now have it in the same folder called test.txt. I use this code to run it:
    package RPGApplicatie;
    public class RPGApplicatie {
         public static void main(String[] args) throws ClassNotFoundException, RuntimeException, InstantiationException, IllegalAccessException {
              Karakters.readFile("test.txt");
    }Thanks in advance! If more info is needed I can post that.
    Regards,
    Sander

    I assume you have defined your Human and Orc classes to include fields name, experience, etc and a constructor that takes these values as parameters?
    You can remove the Class.forName() method altogether. Example:
    int count = file.readInt();
    // define variables for Karakter values (name, experience etc.)
    for (int i = 0; i < count; i++)
      String characterClass = file.readLine();
      // read common character components
      if (characterClass.equals("Human")
        // read human specific components
        karakters.add(new Human(...));
      if (characterClass.equals("Orc")
        // create Orc
    //...Cheers

  • My computer screen keeps going blank and then going back to the box where I put my password in to start my comp. Why is this happening?

    My computer (Macbook) was working fine this am. I left it for an hour and then came back and the screen was black (always does that as the screensaver hardly ever works). I moved the mouse to wake it up and everything was normal. I went to adjust the volume and the screen went blank and the main page with the box where I put my password in when I first start my comp appeared. I put my password in and everything was normal again. I opened a window in Safari and before it loaded completely the same thing happened, the screen went blank and went back to the password box. Does anyone know why this is happening? I don't have an external hard drive or any blank flash drives so I can't back anything up right now and am afraid I'm going to lose everything. Thank you

    Sounds like hardware failure, called boot loop. Call Apple and or go on apple.com and make Genius Bar appointment to have your iphone reviewed by a Tech. Provided you iphone shows no physical or liquid damage they will take care of you, or if you have Apple Care Plus
    Genius Bar Rerservation :  http://www.apple.com/retail/geniusbar/

  • Need help - how to run this particular method in the main method?

    Hi all,
    I have a problem with methods that involves objects such as:
    public static Animal get(String choice) { ... } How do we return the "Animal" type object? I understand codes that return an int or a String but when it comes to objects, I'm totally lost.
    For example this code:
    import java.util.Scanner;
    interface Animal {
        void soundOff();
    class Elephant implements Animal {
        public void soundOff() {
            System.out.println("Trumpet");
    class Lion implements Animal {
        public void soundOff() {
            System.out.println("Roar");
    class TestAnimal {
        public static void main(String[] args) {
            TestAnimal ta = new TestAnimal();
            ta.get(); // error
            // doing Animal a = new Animal() is horrible... :(                   
        public static Animal get(String choice) {
            Scanner myScanner = new Scanner(System.in);
            choice = myScanner.nextLine();
            if (choice.equalsIgnoreCase("meat eater")) {
                return new Lion();
            } else {
                return new Elephant();
    }Out of desperation, I tried "Animal a = new Animal() ", and it was disastrous because an interface cannot be instantiated. :-S And I have no idea what else to put in my main method to get the code running. Need some help please.
    Thank you.

    Hi paulcw,
    Thank you. I've modified my code but it still doesn't print "roar" or "trumpet". When it returns a Lion or an Elephant, wouldn't the soundOff() method get printed too?
    refactored:
    import java.util.Scanner;
    interface Animal {
        void soundOff();
    class Elephant implements Animal {
        public void soundOff() {
            System.out.println("Trumpet");
    class Lion implements Animal {
        public void soundOff() {
            System.out.println("Roar");
    class TestAnimal {
        public static void main(String[] args) {
            Animal a = get();
        public static Animal get() {
            Scanner myScanner = new Scanner(System.in);
            System.out.println("Meat eater or not?");
            String choice = myScanner.nextLine();
            if (choice.equalsIgnoreCase("meat eater")) {
                return new Lion();
            } else {
                return new Elephant();
    }The soundOff() method should override the soundOff(); method in the interface, right? So I'm thinking, it should print either "roar" or "trumpet" but it doesn't. hmm..

  • Where to put javascript code?

    Hello,
    I am trying to set some columns in a list as "read-only" and is using the following code:
    <script type=”text/javascript”>
    function SetReadOnly()
    var elements=document.getElementById(’4_ctl00_ctl00_TextField’);
    elements.readOnly=true;
    _spBodyOnLoadFunctionNames.push(“SetReadOnly()”);
    </script>
    But I am not sure where to put the code in. Should I put it in the space in Content Editor Web Part,
    or through a link to a txt file, or in "Edit HTML"? I've tried them but none works.
    Thanks a lot!
    Patrick

    You can try this:
    1) Open your Sharepoint List. Go to List edit view.
    2) On right side of Ribbon you will find "Form Web Parts" option as shown in figure.
    3) Choose your List form which you want to edit.
    4) Now you can add web part in new window.
    5) Add Content Editor Web part.
    6) In content editor web part add the path of your "txt" file in which you have written your script, for eg.
    <!DOCTYPE html>
    <html>
    <body>
    <script type=”text/javascript”>
    function SetReadOnly()
    var elements=document.getElementById('4_ctl00_ctl00_TextField');
    elements.readOnly=true;
    _spBodyOnLoadFunctionNames.push("SetReadOnly()");
    </script>
    </body>
    </html>
    I haven't tried this method so I am not sure but hope it works...:D
    ***If my post is answer for your query please mark as answer***
    ***If my answer is helpful please vote***

  • 10g UIX Where to put ResourceBundle?

    I'm looking at putting all my Strings in a ResourceBundle for my UIX pages. I've read the documentation for Internationalization, but I think the piece that I'm missing is where to put the properties file. Say I've got a file called 'strings.properties', and my provider looks like this:
    <provider>
         <data name="bundle" >
              <bundle class="strings.properties" />
         </data>
    </provider>Then where in the JDev project do I need to have the file in order for it to get deployed properly and found by the UIX framework at runtime?
    Also, just to be sure I'm not going crazy, I know that the documentation and even the bundle tag say to specify a Class, and I just noticed that the ResourceBundle javadoc also says that the 'baseName' parameter to the static 'getBundle' method should be a 'fully qualified class name', but I've always just given it a filename of a properties file before. So I'm assuming that the 'class' parameter to the bundle tag can be a properties filename -- is this correct?

    Whoops! Of course, the argument to the bundle class attribute should just be 'strings'.
    After some experimentation, I discovered that if I put the properties file at the root of the 'src' directory in my JDev project, then it gets transferred to the 'classes' output directory when I compile. This works for running my project in the Embedded OC4J. I haven't tried deploying it to any other app server yet. Is this the right place?

  • Java programming language main method question?

    Hello everyone I am quite new to the Java programming language and I have a question here concerning my main method. As you can see I am calling 4 others methods with my main method. What does the null mean after I call the method? I really don't understand is significance, what else could go there besides null?
    public static void main(String[] args)
              int cansPerPack = 6;
              System.out.println(cansPerPack);
              int cansPerCrate = 4* cansPerPack;
              System.out.println(cansPerCrate);
              have_fun(null);
              user_input(null);
              more_java(null);
              string_work(null);
         }Edited by: phantomswordsmen on Jul 25, 2010 4:29 PM

    phantomswordsmen wrote:
    ..As you can see I am calling 4 others methods with my main method. 'Your' main method? Your questions indicate that you did not write the code, who did?
    ..What does the null mean after I call the method?.. 'null' is being passed as an argument to the method, so there is no 'after the method' about it.
    ..I really don't understand is significance, what else could go there besides null? That would depend on the method signatures that are not shown in the code snippet posted. This is one of many reasons that I recommend people to post an SSCCE *(<- link).*
    BTW - method names like have_fun() do not follow the common nomenclature, and are not good code for a newbie to study. The code should be put to the pointy end of your sword.

  • No main method error

    Hello I'm using net beans v4, and I'm getting an error after I compile and try to run my code
    It says that my .java is missing a main method, I'm lost
    Below is the code. I also have a form.
    I dont know what the main method is or what goes in it.
    (I've tried the beginner tutorial for netbeans which creates a program called colourswitch)
    any help would be appreciated.
    thx
    * user_authorization.java
    * Created on March 6, 2005, 8:19 PM
    * @author BM
    * misrab at mcmaster dot ca
    public class user_authorization extends javax.swing.JPanel {
    /** Creates new form user_authorization */
    public user_authorization() {
    initComponents();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents() {                         
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jPasswordField1 = new javax.swing.JPasswordField();
    jButton1 = new javax.swing.JButton();
    setLayout(null);
    jLabel1.setFont(new java.awt.Font("Arial", 1, 18));
    jLabel1.setText("User Authorization");
    add(jLabel1);
    jLabel1.setBounds(120, 50, 170, 22);
    jLabel2.setText("Please enter your user name and password to enter the system.");
    add(jLabel2);
    jLabel2.setBounds(40, 80, 350, 15);
    jLabel3.setText("UserName");
    add(jLabel3);
    jLabel3.setBounds(110, 140, 70, 15);
    jLabel4.setText("PassWord");
    add(jLabel4);
    jLabel4.setBounds(110, 170, 60, 15);
    add(jTextField1);
    jTextField1.setBounds(210, 140, 60, 20);
    add(jPasswordField1);
    jPasswordField1.setBounds(210, 170, 60, 22);
    jButton1.setText("Access System");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton1ActionPerformed(evt);
    add(jButton1);
    jButton1.setBounds(140, 210, 110, 23);
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
    // TODO add your handling code here:
    //Declare the variables
    String strUserName;
    String strPassWord;
    //setting textfield to variable name
    strUserName = jTextField1.getText();
    strPassWord = jPasswordField1.getText();
    for (int i=1; i<=3; i=i+1) {
    // user authentication module
    if (strUserName == "admin" && strPassWord == "smith" || strUserName == "general" && strPassWord == "thesis")
    { //you can enter system
    System.out.println("system access granted");
    else {
    strUserName = null;
    strPassWord = null;
    jPasswordField1.setEnabled(false);
    jTextField1.setEnabled(false);
    jButton1.setEnabled(false);
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration
    }

    hmm ok..well I remember seeing that in one of the other versions that I had created of my project
    but it was giving me errors at compile time...it would underline all the code after that line...
    The error was saying that all the labels and command buttons I had on the form (that were automatically put in the code, in that light blue area) didn't have an interface.
    What does that mean?
    thx in advance for your help

  • Calling main method of a class

    Hi
    I have to call the Main method of a class in some other class becuass that class is accepting command line aurguments.
    I test it and everything is working fine.
               String[] strings = new String[3];
               strings[0] = "E:/practice.cap";
               strings[1] = "-o";
               strings[2] = "E:/practice.txt";
               Main.main(strings);I now want to know is there any drawback of doing this ?
    BR
    regards

    Muhammad Umer wrote:
    Good Explanation. But my question is not to explain the importance of main method in classes :)As far as the Java language and APIs go, there's nothing wrong with calling main just like any other method, because it is just another method. It's only special to the JVM, and to programmers who assume that it's the entry point to the program.
    As far as Java is concerned, you can call as many mains as you want. The only potential problem arises if some particular main is written in a way that relies on it being the entry point to the whole program. That is, if the author wrote it with the assumption that it would only be called by the JVM at startup time, and would not be called arbitrarily from within your code (EDIT: and if proper behavior relies on that assumption being upheld). However, this is just a particular case of a general issue that we always have to be aware of, namely, make sure you understand how a method is intended to be used, and use it in that fashion, or accept the consequences.
    EDIT: However, having said that, it's unusual to call main explicitly, so if you can, I would suggest pulling the functionality that you want out of that main into a different method, and then both your code and the main can call that method. If you cannot do that, then at the point where you call main, clearly document why you're doing it. Otherwise, whoever reads the code a few months or years from now--maybe somebody else, maybe you--will be wondering if the programmer really knew what he was doing, or if that is a mistake. That kind of second-guessing is the source of a lot of maintenance nightmares.
    Edited by: jverd on Nov 3, 2011 8:43 AM

Maybe you are looking for

  • Xvid and ac3 quicktime codec

    Hi All, got my mini yesterday, hooked it up and all is good. All my movies and tunes are stored on my NAS and sync with front row via aliases. I need an quicktime xvid and ac3 codec that is compatable with intel macs. The regular ones wont work, but

  • Problems with apache

    I downloaded XAMPP Moodle today to do some development and found that apache would not start. It complained that Web Sharing was already turned on in System Preferences and that I should turn it off. When I checked in System Preferences, all indicati

  • Airport - sharing btwn imac & macbook

    i hope someone can help me with this. i have internet on my imac (tiger), and i have set it up to share thru airport to my macbook (leopard). this is fine, i know how to set it up, it works no problemo. but, occasionally, my imac will "turn off" shar

  • Upgrade 2.6 to Solaris 8 OS

    Dear All , I would like to upgrade Sun OS 2.6 to 8 Operating system. if i upgrade a Solaris 2.6 to 8 OS , what will happens to the cron jobs file . will it be there after upgrade ..or should i take any backup and restore . If it so .. please give me

  • How to create a LookUp field, selecting a value from another record type ??

    Hello all, I am looking to create a new field in Opportunity in CRM On Demand where we can give the user an option to select one of the records. Data in this search applet should come from another Record Type in CRM On Demand. I am not able to find a