前提
javafxでテトリスチックなものを作成しているのですが、昨日まで普通に動いていたのに本日実行しようとしたらエラーが出てしまいました。
発生している問題・エラーメッセージ
Exception in Application start method Exception in thread "main" java.lang.IllegalArgumentException: 0 > -4 at java.base/java.util.Arrays.copyOfRange(Arrays.java:3781) at java.base/java.util.Arrays.copyOfRange(Arrays.java:3741) at jdk.compiler/com.sun.tools.javac.launcher.Main.execute(Main.java:427) at jdk.compiler/com.sun.tools.javac.launcher.Main.run(Main.java:192) at jdk.compiler/com.sun.tools.javac.launcher.Main.main(Main.java:132)
該当のソースコード
import java.io.File; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyEvent; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.util.Duration; import javafx.event.EventHandler; import javafx.event.ActionEvent; public class Main extends Application{ //x=0~11,y=0~14 int[][] map = { {1,0,0,0,0,0,0,2,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,0,0,0,0,1}, {1,1,1,1,1,1,1,1,1,1,1,1}, }; int HeroX = 5; int HeroY = 0; int x = 1000; Group root = new Group(); Image wall = new Image(new File(".\\wall.jpg").toURI().toString()); Image floor = new Image(new File(".\\floor.jpg").toURI().toString()); Image Hero = new Image(new File(".\\Hero.jpg").toURI().toString()); Scene scene = new Scene(root,300,300); @Override public void start (Stage s) throws Exception{ s.setTitle("プロトタイプ"); scene.setFill(Color.GRAY); s.setScene(scene); printMap(); Timeline timer = new Timeline(new KeyFrame(Duration.millis(x),new EventHandler<ActionEvent>(){ @Override public void handle(ActionEvent event){ if(HeroY == 13 || map[HeroY+1][HeroX] == 2){ map[HeroY][HeroX] = 2; HeroY = 0; HeroX = 7; printMap(); } HeroY = Math.min(13,HeroY+=1); map[HeroY][HeroX] = 2; map[HeroY-1][HeroX] = 0; printMap(); scene.setOnKeyPressed(e -> press(e)); } })); timer.setCycleCount(Timeline.INDEFINITE); timer.play(); s.show(); } void press(KeyEvent event){ map[HeroY][HeroX] = 0; switch (event.getCode()){ case DOWN: if(map[HeroY+1][HeroX] == 2) { map[HeroY][HeroX] = 2; break; } HeroY = Math.min(13,HeroY+=1); map[HeroY][HeroX] = 2; break; case LEFT: HeroX = Math.max(1,HeroX-=1); map[HeroY][HeroX] = 2; break; case RIGHT: HeroX = Math.min(10,HeroX+=1); map[HeroY][HeroX] = 2; break; default: return; } printMap(); } void printMap(){ root.getChildren().clear(); for(int i=0; i<12; i++){ for(int j=0; j<15; j++){ ImageView imv = new ImageView(); if (map[i][j] == 1) imv = new ImageView(wall); else if(map[i][j] == 0) imv = new ImageView(floor); else if(map[i][j] == 2) imv = new ImageView(Hero); imv.setX(1+j*16); imv.setY(1+i*16); root.getChildren().add(imv); } } } public static void main(String[] args){ launch(Main.class); } }
試したこと
昨日からvscodeを何もいじっていないので解決方法がわからなくて困っています。強いて言うなら一回vscodeを再起動したくらいです。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。