multithreading - Exception in Application constructor -


i wanna write snake game javafx , there exception don't know , want know how fix it. ( know it's not complete yet )

and want know , class extends application ( start override ) main in other programs? see , here not static void main bc didn't need, if want add main shoud do?

it's exeption...

 exception in application constructor exception in thread "main" java.lang.nosuchmethodexception: main_snake.main([ljava.lang.string;)     @ java.lang.class.getmethod(class.java:1819)     @ com.intellij.rt.execution.application.appmain.main(appmain.java:125) 

and code :

import javafx.animation.animationtimer; import javafx.application.application; import javafx.event.eventhandler; import javafx.scene.scene; import javafx.scene.canvas.canvas; import javafx.scene.canvas.graphicscontext; import javafx.scene.input.keyevent; import javafx.scene.layout.borderpane; import javafx.scene.paint.color; import javafx.stage.stage;  import java.util.arraylist;  /**  * created nadia on 1/5/2016.  */    public class main_snake extends application{     snake snake = new snake();     apple apple = new apple();      canvas canvas = new canvas(800, 600);     boolean gonorth = true, gosouth, gowest, goeast;     int x, y = 0; // marbut apple     boolean j = false;     //    int gm_ov = 0; // vase game on shodan     arraylist<integer> x = new arraylist<integer>();     arraylist<integer> y = new arraylist<>();       @override     public void start(stage primarystage) throws exception {          borderpane b = new borderpane(canvas);         scene scene = new scene(b, 800, 600);         primarystage.setscene(scene);         primarystage.show();          //keyboard(scene);          scene.setonkeypressed(new eventhandler<keyevent>() {             @override             public void handle(keyevent e) {                 switch (e.gettext()) {                     case "w":                         if (!gosouth) {                             gonorth = true;                             gosouth = false;                             gowest = false;                             goeast = false;                         }                         break;                     case "s":                         if (!gonorth) {                             gosouth = true;                             gonorth = false;                             gowest = false;                             goeast = false;                         }                         break;                     case "a":                         if (!goeast) {                             gowest = true;                             goeast = false;                             gosouth = false;                             gonorth = false;                         }                         break;                     case "d":                         if (!gowest) {                             goeast = true;                             gowest = false;                             gosouth = false;                             gonorth = false;                         }                         break;                  }             }         });           play();     }      public void play(){         animationtimer timer = new animationtimer() {               private long lastupdate = 0;              @override             public void handle(long now) {                  if (now - lastupdate >= 40_000_000) {  // payin avordane sor@                      snake.pos_s(); // har bar mar rasm mishe bad az move va ye sib ba x,y khodesh rasm mishe tu tabe move dar morede tabe point hast                     apple.pos_a();                     apple.random_pos();                     snake.move();                      lastupdate = now; // sor@                 }              }         };          timer.start();      }    /* public void keyboard(scene scene) {     }*/ }   class apple extends main_snake {        public void random_pos() {          if (j == false) { // ye sib bede ke ru mar nabashe ( rasmesh tu rasme )              {                  x = (int) (math.random() * 790 + 1);                  y = (int) (math.random() * 590 + 1);              } while (x.indexof(x) != -1 && y.get(x.indexof(x)) == y || x % 10 != 0 || y % 10 != 0);                         /*inja aval chek kardam tu araylist x hast ya na ag bud sharte aval ok hala sharte ke tu y ham mibinim tu hamun shomare khune                         y barabare y mast ag bud pas ina bar ham montabeghan va sharte dovom ham ok . 2 sharte akhar ham vase ine ke mare ma faghat mazrab                         haye 10 , pas ta vaghti in se shart bargharare jahayie ke ma nemikhaym va hey jaye dg mide*/               j = true;          }       }       public void pos_a() {          graphicscontext gc = canvas.getgraphicscontext2d();          gc.setfill(color.black);          gc.fillrect(x, y, 10, 10);       }       public void point() {          if (x.get(0) == x && y.get(0) == y) {              j = false;          }      }  }    class snake extends main_snake {     snake(){   //cunstructor          x.add(400);         y.add(300);          x.add(400);         y.add(310);          x.add(400);         y.add(320);           x.add(400);         y.add(330);           x.add(400);         y.add(340);     }      public void pos_s(){         graphicscontext gc = canvas.getgraphicscontext2d();         gc.setfill(color.white);         gc.fillrect(0, 0, canvas.getwidth(), canvas.getheight());         apple.pos_a();          // keshidane mar (body yeki ezafe tar az adade morabaa mide)         (int = x.size() - 1; >= 0; i--)             gc.fillrect(x.get(i), y.get(i), 10, 10);      }     public void move(){          int px = x.get(x.size() - 1);         int py = y.get(y.size() - 1);          (int z = x.size() - 1 ; z > 0 ; z--){             x.remove(z);             x.add(z , x.get(z-1) )   ;             y.remove(z);             y.add(z , y.get(z-1) )   ;          }          if (gonorth) {             y.add(0 , y.get(0) - 10);             y.remove(1);          }         if (gosouth) {             y.add(0 , y.get(0) + 10);             y.remove(1);          }         if (goeast)  {             x.add(0 , x.get(0) + 10);             x.remove(1);          }         if (gowest)  {             x.add(0 , x.get(0) - 10);             x.remove(1);          }          apple.point();        // emtiaz gerefte         if ( j == false)    {             x.add(px);             y.add(py);         }          if ( x.get(0) > 790 ){             x.remove(0);             x.add(0 , 0);         }         if ( x.get(0) <  0  ){             x.remove(0);             x.add(0 , 800);         }         if ( y.get(0) > 590 ){             y.remove(0);             y.add(0 , 0);         }         if ( y.get(0) <  0  ){             y.remove(0);             y.add(0 , 600);         }      } } 

the standard oracle java runtime environment can execute application subclasses directly command line, if not contain main method. assuming using standard jre, command line can execute

java main_snake 

and run (assuming no other errors, etc).

other environments, , ides, don't support execution mode, if want run in environments (including running in eclipse, example), need main(...) method launches javafx application. add

public static void main(string[] args) {     launch(args); } 

to main_snake class.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -