2015-09-20 72 views
0

我正在使用Processing庫在Eclipse Mars中製作遊戲。我在其他地方製作了這款遊戲,並且運行良好。在我將我的閃存驅動器中的文件複製並粘貼到Eclipse中的文件夾後沒有錯誤。當我試圖運行它時,它說:「選擇無法啓動,並且最近沒有啓動。」最近沒有推出,因爲我剛剛得到Eclipse。我的代碼如下:無法運行程序

Main Class: 

    //package dogeball; 

import processing.core.PApplet; 
import processing.core.PImage; 
import java.awt.Color; 
import processing.core.PFont; 

public class Dogeball extends PApplet { 
    Ball ball; 
    Furniture butterChair; 
    Furniture[] bricks; 
    PFont dogefont; 
    float py; 
    float score; 
    boolean game; 
    int checker; 
    boolean mode; 

    PImage img = loadImage("doge.jpg"); 
    PImage img2 = loadImage("doge2.png"); 
    public void setup() { 
     checker = 0; 
     size(300,250); 
     game = false; 
     mode = true; 
     ball = new Ball(this, 100, 225, 0, 0, 10, Color.DARK_GRAY); 
     butterChair = new Furniture(this, 130, 238, 40, 10, Color.YELLOW); 
     py = butterChair.w /2; 
     bricks = new Furniture[56]; 
     dogefont = loadFont("ComicSansMS-48.vlw"); 
     for(int rowNum = 0; rowNum<8; rowNum+= 1) { 

      for(int colNum = 0; colNum<7; colNum += 1){ 

       bricks[7*rowNum + colNum] = new Furniture(this, 10+40*colNum, 10+15*rowNum, 40, 15, Color.red); 
       score = 0; 
      } 
      } 


    } 
    public void draw() { 



     if(game == false) { 
     background(img); 
     fill(0,255,255); 
     textSize(30); 
     textFont(dogefont); 
     text("DogeBall",33, 170); 
     fill(255,255,0); 
     textSize(20); 
     text("Press Space", 120,190); 
     fill(255,0,0); 
     text("Such BrickBreaker", 20, 20); 
     fill(0,0,255); 
     text("Much Atari", 190, 80); 
     fill(0,255,0); 
     text("How Breakout", 150, 230); 
     } 
     if(keyPressed == true) { 
      if (key == ' ') { 
       game = true; 
      } 
     } 

     if(game == true) { 
      if(keyPressed == true) { 
       if (key == 'm') { 
        mode = !mode; 
       } 
      } 
      //checker = 0; 
      background(img); 
      ball.appear(); 
      ball.hover(); 
      butterChair.appear(); 
      if(mode == true) { 
      butterChair.x = mouseX-butterChair.w/2; 
      } 
      if(mode == false) { 
      if(keyPressed == true) { 
       if (key == CODED) { 
        if (keyCode == LEFT){ 
         butterChair.x -= 3; 
        } 
       } 
      } 
      if(keyPressed == true) { 
       if (key == CODED) { 
        if (keyCode == RIGHT){ 
         butterChair.x += 3; 
        } 
       } 
      } 
      } 
      if(butterChair.x <= 0) { 
       butterChair.x = 0; 
      } 
      if(butterChair.x >= width - butterChair.w) { 
      butterChair.x = width - butterChair.w; 
      } 
      textFont(dogefont); 
      fill(255,0,255); 
      text("Much Doge", 12, 160); 

      fill(255,0,0); 
      textSize(20); 
      text("M to toggle mouse mode.", 20,200); 

      fill(0); 
      textSize(10); 
      text("You might have to press twice", 10,220); 

      fill(0,0,255); 
      textSize(20); 
      text("Press S to Start", 150, 230); 

      if (keyPressed == true) { 
       if (key == 's' || key == 'S'){ 
        ball.vy = 2; 
        ball.vx = 1; 
       } 
      } 

      /*if(mousePressed == true) { 
       ball.vx = 0; 
       ball.vy = 0; 
      }*/ 

      for(int i = 0; i<56; i+= 1) { 
       bricks[i].appear(); 
      } 


     } 

     detectCollision(); 

     if(ball.y >= height) { 
      checker = 0; 
      if(checker ==0){ 
      background(img); 
      ball.vx = 0; 
      ball.vy = 0; 
      textSize(30); 
      fill(255,0,0); 
      game = false; 
      text("Such Sorry", 130, 160); 

      fill(0,255,255); 
      text("Much Game Over", 20, 215); 

      fill(255,255,0); 
      text("So Losing", 10, 30); 

      textSize(20); 
      text("Press P to Play Again", 20, 245); 
      } 
      if(keyPressed == true) { 
       if(key == 'p') { 
        game = true; 
        ball.x = 100; 
        ball.y = 225; 
        checker = 1; 

        for(int rowNum = 0; rowNum<8; rowNum+= 1) { 

         for(int colNum = 0; colNum<7; colNum += 1){ 

          bricks[7*rowNum + colNum] = new Furniture(this, 10+40*colNum, 10+15*rowNum, 40, 15, Color.red); 
          score = 0; 
         } 
        } 

       } 
      } 
     } 





    } 



    void detectCollision() { 


     if(keyPressed == true) { 
      if(key == '-') 
        { 
       for(int cCode = 0; cCode < 56; cCode += 1) { 
        Furniture b = bricks[cCode]; 
        b.x = width * 2; 
        b.y = height * 2; 
        score = 56; 
       } 
      }} 



     if(ball.x >= butterChair.x && 
       ball.x <= butterChair.x + butterChair.w && 
       ball.y + ball.s /2 > butterChair.y) { 
      ball.vy *= -1; 
     } 

     for(int i = 0; i<bricks.length; i+= 1) { 
      Furniture b = bricks[i]; 
      if(ball.x >= b.x && ball.x <= b.x+b.w && ball.y-ball.s/2 <= b.y) { 
       b.y = height * 2; 
       b.x = width * 2; 
       ball.vy *= -1; 
       score += 1; 
      } 
      if(score == 56){ 
       background(img); 
       ball.vx = 0; 
       ball.vy = 0; 
       fill(255,0,0); 
       textSize(20); 
       text("Such Winning!", 20, 20); 
       textSize(40); 
       fill(0,255,0); 
       text("Much Congrats!",12 ,160); 
       textSize(20); 

       fill(255,0,255); 
       text("Press P to Play Again", 20, 245); 

       if(keyPressed == true) { 
        if(key == 'p') { 
         game = true; 
         ball.x = 100; 
         ball.y = 225; 
         checker = 1; 

         for(int rowNum = 0; rowNum<8; rowNum+= 1) { 

          for(int colNum = 0; colNum<7; colNum += 1){ 

           bricks[7*rowNum + colNum] = new Furniture(this, 10+40*colNum, 10+15*rowNum, 40, 15, Color.red); 
           score = 0; 
         } 
        } 
       } 
      } 
     } 
     } 
    } 
    static public void main(String args[]) { 
     PApplet.main("Dogeball"); 
    } 

} 

Ball Class: 

    //package dogeball; 

import java.awt.Color; 

import processing.core.PApplet; 

public class Ball extends PApplet { 
    float x; 
    float y; 
    float vx; 
    float vy; 
    float s; 
    Color c; 
    PApplet p; 

Ball(PApplet pApp, float xLocation, float yLocation, float xSpeed, float ySpeed, float size, Color shade){ 
    x = xLocation; 
    y = yLocation; 
    vx = xSpeed; 
    vy = ySpeed; 
    s = size; 
    c = shade; 
    p = pApp; 
    } 

    void hover() { 
     x += vx; 
     y += vy; 

     if(x< 0 || x> p.width) { 
      vx *= -1; 
     } 

     if(y< 0) { 
      vy *= -1; 
     } 
    } 
    void appear() { 
     p.fill(c.getRGB()); 
     p.ellipse(x,y,s,s); 
    } 


} 

Paddle Class: 

    //package dogeball; 

import java.awt.Color; 
import processing.core.PApplet; 

public class Furniture extends PApplet { 
float x; 
float y; 
float w; 
float h; 
Color c; 
PApplet p; 

Furniture(PApplet PApp, float locationX, float locationY, float fWidth, float fHeight, Color shade) { 
    x = locationX; 
    y = locationY; 
    w = fWidth; 
    h = fHeight; 
    c = shade; 
    p = PApp; 
} 

void appear() { 
    p.fill(c.getRGB()); 
    p.rect(x,y,w,h); 
    } 

} 

回答

1

你有可能在項目樹或者運行配置選擇了錯誤的項目設置到另一個項目,因爲你還沒有運行它。

無論哪種方式,你必須右擊項目樹您的項目文件夾,然後找到運行方式> Java小程序


另一種方法是添加 main函數,就像你已經做的那樣,並且運行如 Java應用程序。而是採用了目前主流的功能,你可以嘗試使用下面的代碼,看看它在目前的模式,看看它的工作原理:

public static void main(String args[]) { 
    PApplet.main(new String[] { "--present", "Dogeball" }); 
} 
+0

我試着右擊該項目並運行它作爲一個Java小程序,但它說「選擇不包含小程序。」 – brsgaming804

+0

更新:我做到了,現在它在控制檯中顯示以下內容,並且不運行該程序。 – brsgaming804

+0

異常在線程 「主要」 java.lang.NoClassDefFoundError:Dogeball(錯誤名稱:DogeBall) \t在java.lang.ClassLoader.defineClass1(本機方法) \t在需要java.lang.ClassLoader.defineClass(來源不明) \t在java.security.SecureClassLoader.defineClass(未知來源) \t在java.net.URLClassLoader.defineClass(未知來源) \t在java.net.URLClassLoader.access $ 100(未知源) \t在java.net.URLClassLoader的$ 1 .run(Unknown Source) \t at java.net.URLClassLoader $ 1.run(Unknown Source) \t at java.security.Access Controller.doPrivileged(本機方法) – brsgaming804